Annotation of gdb/infcmd.c, revision 1.1.1.5

1.1       root        1: /* Memory-access and commands for inferior process, for GDB.
1.1.1.3   root        2:    Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
1.1       root        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 "symtab.h"
                     24: #include "param.h"
                     25: #include "frame.h"
                     26: #include "inferior.h"
                     27: #include "environ.h"
                     28: #include "value.h"
                     29: 
                     30: #include <stdio.h>
                     31: #include <signal.h>
                     32: #include <sys/param.h>
                     33: 
                     34: extern char *sys_siglist[];
                     35: 
                     36: #define ERROR_NO_INFERIOR \
                     37:    if (inferior_pid == 0) error ("The program is not being run.");
                     38: 
                     39: /* String containing arguments to give to the program,
                     40:    with a space added at the front.  Just a space means no args.  */
                     41: 
                     42: static char *inferior_args;
                     43: 
1.1.1.2   root       44: /* File name for default use for standard in/out in the inferior.  */
                     45: 
                     46: char *inferior_io_terminal;
                     47: 
1.1       root       48: /* Pid of our debugged inferior, or 0 if no inferior now.  */
                     49: 
                     50: int inferior_pid;
                     51: 
                     52: /* Last signal that the inferior received (why it stopped).  */
                     53: 
                     54: int stop_signal;
                     55: 
                     56: /* Address at which inferior stopped.  */
                     57: 
                     58: CORE_ADDR stop_pc;
                     59: 
                     60: /* Stack frame when program stopped.  */
                     61: 
                     62: FRAME stop_frame;
                     63: 
                     64: /* Number of breakpoint it stopped at, or 0 if none.  */
                     65: 
                     66: int stop_breakpoint;
                     67: 
                     68: /* Nonzero if stopped due to a step command.  */
                     69: 
                     70: int stop_step;
                     71: 
                     72: /* Nonzero if stopped due to completion of a stack dummy routine.  */
                     73: 
                     74: int stop_stack_dummy;
                     75: 
                     76: /* Range to single step within.
                     77:    If this is nonzero, respond to a single-step signal
                     78:    by continuing to step if the pc is in this range.  */
                     79: 
                     80: CORE_ADDR step_range_start; /* Inclusive */
                     81: CORE_ADDR step_range_end; /* Exclusive */
                     82: 
                     83: /* Stack frame address as of when stepping command was issued.
                     84:    This is how we know when we step into a subroutine call,
                     85:    and how to set the frame for the breakpoint used to step out.  */
                     86: 
                     87: CORE_ADDR step_frame;
                     88: 
                     89: /* 1 means step over all subroutine calls.
                     90:    -1 means step over calls to undebuggable functions.  */
                     91: 
                     92: int step_over_calls;
                     93: 
                     94: /* If stepping, nonzero means step count is > 1
                     95:    so don't print frame next time inferior stops
                     96:    if it stops due to stepping.  */
                     97: 
                     98: int step_multi;
                     99: 
                    100: /* Environment to use for running inferior,
                    101:    in format described in environ.h.  */
                    102: 
                    103: struct environ *inferior_environ;
                    104: 
                    105: CORE_ADDR read_pc ();
1.1.1.2   root      106: struct command_line *get_breakpoint_commands ();
1.1       root      107: 
                    108: START_FILE
                    109: 
                    110: int
                    111: have_inferior_p ()
                    112: {
                    113:   return inferior_pid != 0;
                    114: }
                    115: 
                    116: static void 
                    117: set_args_command (args)
                    118:      char *args;
                    119: {
                    120:   free (inferior_args);
                    121:   if (!args) args = "";
                    122:   inferior_args = concat (" ", args, "");
                    123: }
1.1.1.3   root      124: 
1.1.1.2   root      125: void
                    126: tty_command (file)
                    127:      char *file;
                    128: {
                    129:   if (file == 0)
                    130:     error_no_arg ("terminal name for running target process");
                    131: 
                    132:   inferior_io_terminal = savestring (file, strlen (file));
                    133: }
1.1       root      134: 
                    135: static void
                    136: run_command (args, from_tty)
                    137:      char *args;
                    138:      int from_tty;
                    139: {
                    140:   extern char **environ;
                    141:   register int i;
                    142:   char *exec_file;
                    143:   char *allargs;
                    144: 
                    145:   extern int sys_nerr;
                    146:   extern char *sys_errlist[];
                    147:   extern int errno;
                    148: 
                    149:   dont_repeat ();
                    150: 
                    151:   if (inferior_pid)
                    152:     {
                    153:       if (query ("The program being debugged has been started already.\n\
                    154: Start it from the beginning? "))
                    155:        kill_inferior ();
                    156:       else
                    157:        error ("Program already started.");
                    158:     }
                    159: 
1.1.1.3   root      160:   if (remote_debugging)
1.1       root      161:     {
1.1.1.3   root      162:       free (allargs);
                    163:       if (from_tty)
                    164:        {
                    165:          printf ("Starting program: %s%s\n",
                    166:                  exec_file, inferior_args);
                    167:          fflush (stdout);
                    168:        }
1.1       root      169:     }
1.1.1.3   root      170:   else
                    171:     {
                    172:       if (args)
                    173:        set_args_command (args);
1.1       root      174: 
1.1.1.4   root      175:       exec_file = (char *) get_exec_file (1);
1.1.1.3   root      176:       if (from_tty)
                    177:        {
                    178:          printf ("Starting program: %s%s\n",
                    179:                  exec_file, inferior_args);
                    180:          fflush (stdout);
                    181:        }
                    182: 
                    183:       allargs = concat ("exec ", exec_file, inferior_args);
                    184:       inferior_pid = create_inferior (allargs, environ_vector (inferior_environ));
                    185:     }
1.1       root      186: 
                    187:   clear_proceed_status ();
                    188: 
                    189:   start_inferior ();
                    190: }
                    191: 
1.1.1.2   root      192: void
1.1       root      193: cont_command (proc_count_exp, from_tty)
                    194:      char *proc_count_exp;
                    195:      int from_tty;
                    196: {
                    197:   ERROR_NO_INFERIOR;
                    198: 
                    199:   clear_proceed_status ();
                    200: 
                    201:   /* If have argument, set proceed count of breakpoint we stopped at.  */
                    202: 
                    203:   if (stop_breakpoint && proc_count_exp)
                    204:     {
                    205:       set_ignore_count (stop_breakpoint,
                    206:                        parse_and_eval_address (proc_count_exp) - 1,
                    207:                        from_tty);
                    208:       if (from_tty)
                    209:        printf ("  ");
                    210:     }
                    211: 
                    212:   if (from_tty)
                    213:     printf ("Continuing.\n");
                    214: 
                    215:   proceed (-1, -1, 0);
                    216: }
1.1.1.2   root      217: 
1.1       root      218: /* Step until outside of current statement.  */
                    219: static void step_1 ();
1.1.1.2   root      220: 
1.1       root      221: static void
                    222: step_command (count_string)
                    223: {
                    224:   step_1 (0, 0, count_string);
                    225: }
                    226: 
                    227: /* Likewise, but skip over subroutine calls as if single instructions.  */
                    228: 
                    229: static void
                    230: next_command (count_string)
                    231: {
                    232:   step_1 (1, 0, count_string);
                    233: }
                    234: 
                    235: /* Likewise, but step only one instruction.  */
                    236: 
                    237: static void
                    238: stepi_command (count_string)
                    239: {
                    240:   step_1 (0, 1, count_string);
                    241: }
                    242: 
                    243: static void
                    244: nexti_command (count_string)
                    245: {
                    246:   step_1 (1, 1, count_string);
                    247: }
                    248: 
                    249: static void
                    250: step_1 (skip_subroutines, single_inst, count_string)
                    251:      int skip_subroutines;
                    252:      int single_inst;
                    253:      char *count_string;
                    254: {
                    255:   register int count = 1;
                    256: 
                    257:   ERROR_NO_INFERIOR;
                    258:   count = count_string ? parse_and_eval_address (count_string) : 1;
                    259: 
                    260:   for (; count > 0; count--)
                    261:     {
                    262:       clear_proceed_status ();
                    263: 
                    264:       step_frame = get_current_frame ();
                    265: 
                    266:       if (! single_inst)
                    267:        {
                    268:          find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
                    269:          if (step_range_end == 0)
                    270:            {
                    271:              terminal_ours ();
                    272:              error ("Current function has no line number information.");
                    273:            }
                    274:        }
                    275:       else
                    276:        {
                    277:          /* Say we are stepping, but stop after one insn whatever it does.
                    278:             Don't step through subroutine calls even to undebuggable functions.  */
                    279:          step_range_start = step_range_end = 1;
                    280:          if (!skip_subroutines)
                    281:            step_over_calls = 0;
                    282:        }
                    283: 
                    284:       if (skip_subroutines)
                    285:        step_over_calls = 1;
                    286: 
                    287:       step_multi = (count > 1);
                    288:       proceed (-1, -1, 1);
                    289:       if (! stop_step)
                    290:        break;
                    291:     }
                    292: }
                    293: 
                    294: /* Continue program at specified address.  */
                    295: 
                    296: static void
                    297: jump_command (arg, from_tty)
                    298:      char *arg;
                    299:      int from_tty;
                    300: {
                    301:   register CORE_ADDR addr;
1.1.1.5 ! root      302:   struct symtabs_and_lines sals;
1.1       root      303:   struct symtab_and_line sal;
                    304: 
                    305:   ERROR_NO_INFERIOR;
                    306: 
                    307:   if (!arg)
                    308:     error_no_arg ("starting address");
                    309: 
1.1.1.5 ! root      310:   sals = decode_line_spec (arg, 1);
        !           311:   if (sals.nelts != 1)
        !           312:     {
        !           313:       error ("Unreasonable jump request");
        !           314:     }
        !           315: 
        !           316:   sal = sals.sals[0];
        !           317:   free (sals.sals);
1.1       root      318: 
                    319:   if (sal.symtab == 0 && sal.pc == 0)
                    320:     error ("No source file has been specified.");
                    321: 
                    322:   if (sal.pc == 0)
                    323:     sal.pc = find_line_pc (sal.symtab, sal.line);
                    324: 
                    325:   {
                    326:     struct symbol *fn = get_frame_function (get_current_frame ());
                    327:     struct symbol *sfn = find_pc_function (sal.pc);
                    328:     if (fn != 0 && sfn != fn
1.1.1.4   root      329:        && ! query ("Line %d is not in `%s'.  Jump anyway? ",
1.1       root      330:                    sal.line, SYMBOL_NAME (fn)))
                    331:       error ("Not confirmed.");
                    332:   }
                    333: 
                    334:   if (sal.pc == 0)
                    335:     error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename);
                    336: 
                    337:   addr = sal.pc;
                    338: 
                    339:   clear_proceed_status ();
                    340: 
                    341:   if (from_tty)
                    342:     printf ("Continuing at 0x%x.\n", addr);
                    343: 
                    344:   proceed (addr, 0, 0);
                    345: }
                    346: 
                    347: /* Continue program giving it specified signal.  */
                    348: 
                    349: static void
                    350: signal_command (signum_exp, from_tty)
                    351:      char *signum_exp;
                    352:      int from_tty;
                    353: {
                    354:   register int signum;
                    355: 
                    356:   dont_repeat ();              /* Too dangerous.  */
                    357:   ERROR_NO_INFERIOR;
                    358: 
                    359:   if (!signum_exp)
                    360:     error_no_arg ("signal number");
                    361: 
                    362:   signum = parse_and_eval_address (signum_exp);
                    363: 
                    364:   clear_proceed_status ();
                    365: 
                    366:   if (from_tty)
                    367:     printf ("Continuing with signal %d.\n", signum);
                    368: 
                    369:   proceed (stop_pc, signum, 0);
                    370: }
                    371: 
                    372: /* Execute a "stack dummy", a piece of code stored in the stack
                    373:    by the debugger to be executed in the inferior.
                    374: 
                    375:    To call: first, do PUSH_DUMMY_FRAME.
                    376:    Then push the contents of the dummy.  It should end with a breakpoint insn.
                    377:    Then call here, passing address at which to start the dummy.
1.1.1.2   root      378: 
                    379:    The contents of all registers are saved before the dummy frame is popped
                    380:    and copied into the buffer BUFFER.
1.1       root      381: 
                    382:    The dummy's frame is automatically popped whenever that break is hit.
                    383:    If that is the first time the program stops, run_stack_dummy
                    384:    returns to its caller with that frame already gone.
                    385:    Otherwise, the caller never gets returned to.  */
                    386: 
                    387: /* 4 => return instead of letting the stack dummy run.  */
                    388: 
                    389: static int stack_dummy_testing = 0;
                    390: 
                    391: void
                    392: run_stack_dummy (addr, buffer)
                    393:      CORE_ADDR addr;
                    394:      REGISTER_TYPE *buffer;
                    395: {
                    396:   int saved_pc_changed = pc_changed;
                    397:   int saved_stop_signal = stop_signal;
                    398:   int saved_stop_pc = stop_pc;
                    399:   int saved_stop_frame = stop_frame;
                    400:   int saved_stop_breakpoint = stop_breakpoint;
                    401:   int saved_stop_step = stop_step;
                    402:   int saved_stop_stack_dummy = stop_stack_dummy;
1.1.1.2   root      403:   FRAME saved_selected_frame;
                    404:   int saved_selected_level;
                    405:   struct command_line *saved_breakpoint_commands
                    406:     = get_breakpoint_commands ();
                    407: 
                    408:   record_selected_frame (&saved_selected_frame, &saved_selected_level);
1.1       root      409: 
                    410:   /* Now proceed, having reached the desired place.  */
                    411:   clear_proceed_status ();
                    412:   if (stack_dummy_testing & 4)
                    413:     {
                    414:       POP_FRAME;
                    415:       return;
                    416:     }
                    417:   proceed (addr, 0, 0);
                    418: 
                    419:   if (!stop_stack_dummy)
                    420:     error ("Cannot continue previously requested operation.");
                    421: 
1.1.1.2   root      422:   set_breakpoint_commands (saved_breakpoint_commands);
                    423:   select_frame (saved_selected_frame, saved_selected_level);
1.1       root      424:   stop_signal = saved_stop_signal;
                    425:   stop_pc = saved_stop_pc;
                    426:   stop_frame = saved_stop_frame;
                    427:   stop_breakpoint = saved_stop_breakpoint;
                    428:   stop_step = saved_stop_step;
                    429:   stop_stack_dummy = saved_stop_stack_dummy;
                    430:   pc_changed = saved_pc_changed;
                    431: 
                    432:   /* On return, the stack dummy has been popped already.  */
                    433: 
1.1.1.2   root      434:   bcopy (stop_registers, buffer, sizeof stop_registers);
1.1       root      435: }
                    436: 
                    437: /* "finish": Set a temporary breakpoint at the place
                    438:    the selected frame will return to, then continue.  */
                    439: 
                    440: static void
                    441: finish_command (arg, from_tty)
                    442:      char *arg;
                    443:      int from_tty;
                    444: {
                    445:   struct symtab_and_line sal;
                    446:   register FRAME frame;
                    447:   struct frame_info fi;
                    448: 
                    449:   register struct symbol *function;
                    450: 
                    451:   if (!have_inferior_p ())
                    452:     error ("The program is not being run.");
                    453:   if (arg)
                    454:     error ("The \"finish\" command does not take any arguments.");
                    455: 
                    456:   frame = get_prev_frame (selected_frame);
                    457:   if (frame == 0)
                    458:     error ("\"finish\" not meaningful in the outermost frame.");
                    459: 
                    460:   clear_proceed_status ();
                    461: 
                    462:   fi = get_frame_info (frame);
                    463:   sal = find_pc_line (fi.pc, 0);
                    464:   sal.pc = fi.pc;
                    465:   set_momentary_breakpoint (sal, frame);
                    466: 
                    467:   /* Find the function we will return from.  */
                    468: 
1.1.1.5 ! root      469:   fi = get_frame_info (fi.next_frame, fi.next_next_frame);
1.1       root      470:   function = find_pc_function (fi.pc);
                    471: 
                    472:   if (from_tty)
                    473:     {
                    474:       printf ("Run till exit from ");
                    475:       print_selected_frame ();
                    476:     }
                    477: 
                    478:   proceed (-1, -1, 0);
                    479: 
                    480:   if (stop_breakpoint == -3 && function != 0)
                    481:     {
                    482:       struct type *value_type;
                    483:       register value val;
                    484: 
1.1.1.4   root      485:       value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
                    486:       if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
1.1       root      487:        return;
                    488: 
1.1.1.2   root      489:       val = value_being_returned (value_type, stop_registers);
1.1       root      490:       printf ("Value returned is $%d = ", record_latest_value (val));
1.1.1.4   root      491:       value_print (val, stdout, 0);
1.1       root      492:       putchar ('\n');
                    493:     }
                    494: }
                    495: 
                    496: static void
                    497: program_info ()
                    498: {
                    499:   if (inferior_pid == 0)
                    500:     {
                    501:       printf ("The program being debugged is not being run.\n");
                    502:       return;
                    503:     }
                    504: 
                    505:   printf ("Program being debugged is in process %d, stopped at 0x%x.\n",
                    506:          inferior_pid, stop_pc);
                    507:   if (stop_step)
                    508:     printf ("It stopped after being stepped.\n");
                    509:   else if (stop_breakpoint)
                    510:     printf ("It stopped at breakpoint %d.\n", stop_breakpoint);
                    511:   else if (stop_signal)
                    512:     printf ("It stopped with signal %d (%s).\n",
                    513:            stop_signal, sys_siglist[stop_signal]);
                    514: 
                    515:   printf ("\nType \"info stack\" or \"info reg\" for more information.\n");
                    516: }
                    517: 
                    518: static void
                    519: environment_info (var)
                    520:      char *var;
                    521: {
                    522:   if (var)
                    523:     {
                    524:       register char *val = get_in_environ (inferior_environ, var);
                    525:       if (val)
                    526:        printf ("%s = %s\n", var, val);
                    527:       else
                    528:        printf ("Environment variable \"%s\" not defined.\n", var);
                    529:     }
                    530:   else
                    531:     {
                    532:       register char **vector = environ_vector (inferior_environ);
                    533:       while (*vector)
                    534:        printf ("%s\n", *vector++);
                    535:     }
                    536: }
                    537: 
                    538: static void
                    539: set_environment_command (arg)
                    540:      char *arg;
                    541: {
                    542:   register char *p, *val, *var;
                    543: 
                    544:   if (arg == 0)
                    545:     error_no_arg ("environment variable and value");
                    546: 
                    547:   p = (char *) index (arg, '=');
                    548:   val = (char *) index (arg, ' ');
                    549:   if (p != 0 && val != 0)
                    550:     p = arg + min (p - arg, val - arg);
                    551:   else if (val != 0 && p == 0)
                    552:     p = val;
                    553: 
                    554:   if (p == 0)
                    555:     error ("Space or \"=\" must separate variable name and its value");
                    556:   if (p[1] == 0)
                    557:     error_no_arg ("value for the variable");
                    558:   if (p == arg)
                    559:     error_no_arg ("environment variable to set");
                    560: 
                    561:   val = p + 1;
                    562:   while (*val == ' ' || *val == '\t') val++;
                    563:   while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
                    564: 
                    565:   var = savestring (arg, p - arg);
                    566:   set_in_environ (inferior_environ, var, val);
                    567:   free (var);
                    568: }
                    569: 
                    570: static void
                    571: unset_environment_command (var)
                    572:      char *var;
                    573: {
                    574:   if (var == 0)
                    575:     error_no_arg ("environment variable");
                    576: 
                    577:   unset_in_environ (inferior_environ, var);
                    578: }
                    579: 
                    580: /* Read an integer from debugged memory, given address and number of bytes.  */
                    581: 
                    582: read_memory_integer (memaddr, len)
                    583:      CORE_ADDR memaddr;
                    584:      int len;
                    585: {
                    586:   char cbuf;
                    587:   short sbuf;
                    588:   int ibuf;
                    589:   long lbuf;
                    590: 
                    591:   if (len == sizeof (char))
                    592:     {
                    593:       read_memory (memaddr, &cbuf, len);
                    594:       return cbuf;
                    595:     }
                    596:   if (len == sizeof (short))
                    597:     {
                    598:       read_memory (memaddr, &sbuf, len);
                    599:       return sbuf;
                    600:     }
                    601:   if (len == sizeof (int))
                    602:     {
                    603:       read_memory (memaddr, &ibuf, len);
                    604:       return ibuf;
                    605:     }
                    606:   if (len == sizeof (lbuf))
                    607:     {
                    608:       read_memory (memaddr, &lbuf, len);
                    609:       return lbuf;
                    610:     }
                    611:   error ("Cannot handle integers of %d bytes.", len);
                    612: }
                    613: 
                    614: CORE_ADDR
                    615: read_pc ()
                    616: {
                    617:   return (CORE_ADDR) read_register (PC_REGNUM);
                    618: }
                    619: 
1.1.1.2   root      620: write_pc (val)
                    621:      CORE_ADDR val;
1.1       root      622: {
1.1.1.2   root      623:   write_register (PC_REGNUM, (long) val);
1.1.1.5 ! root      624: #ifdef NPC_REGNUM
        !           625:   write_register (NPC_REGNUM, (long) val+4);
        !           626: #endif
1.1       root      627: }
                    628: 
                    629: char *reg_names[] = REGISTER_NAMES;
                    630: 
                    631: static void
                    632: registers_info (addr_exp)
                    633:      char *addr_exp;
                    634: {
                    635:   register int i;
                    636:   int regnum;
                    637: 
                    638:   if (addr_exp)
                    639:     {
                    640:       if (*addr_exp >= '0' && *addr_exp <= '9')
                    641:        regnum = atoi (addr_exp);
                    642:       else
                    643:        {
                    644:          register char *p = addr_exp;
                    645:          if (p[0] == '$')
                    646:            p++;
                    647:          for (regnum = 0; regnum < NUM_REGS; regnum++)
                    648:            if (!strcmp (p, reg_names[regnum]))
                    649:              break;
                    650:          if (regnum == NUM_REGS)
                    651:            error ("%s: invalid register name.", addr_exp);
                    652:        }
                    653:     }
                    654:   else
                    655:     printf ("Reg\tContents\n\n");
                    656: 
                    657:   for (i = 0; i < NUM_REGS; i++)
                    658:     {
                    659:       unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE];
                    660:       unsigned char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
                    661:       REGISTER_TYPE val;
                    662: 
                    663:       if (addr_exp != 0 && i != regnum)
                    664:        continue;
                    665: 
                    666:       /* On machines with lots of registers, pause every 16 lines
                    667:         so user can read the output.  */
                    668:       if (addr_exp == 0 && i > 0 && i % 16 == 0)
                    669:        {
                    670:          printf ("--Type Return to print more--");
                    671:          fflush (stdout);
                    672:          read_line ();
                    673:        }
                    674: 
                    675:       /* Get the data in raw format, then convert also to virtual format.  */
                    676:       read_relative_register_raw_bytes (i, raw_buffer);
                    677:       REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
                    678: 
                    679:       printf ("%s\t", reg_names[i]);
                    680: 
                    681:       /* If virtual format is floating, print it that way.  */
                    682:       if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT
1.1.1.2   root      683:          && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1.1.1.5 ! root      684:        val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, stdout, 0, 1);
1.1       root      685:       /* Else if virtual format is too long for printf,
                    686:         print in hex a byte at a time.  */
                    687:       else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
                    688:        {
                    689:          register int j;
                    690:          printf ("0x");
                    691:          for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
                    692:            printf ("%02x", virtual_buffer[j]);
                    693:        }
                    694:       /* Else print as integer in hex and in decimal.  */
                    695:       else
                    696:        {
                    697:          long val;
                    698: 
                    699:          bcopy (virtual_buffer, &val, sizeof (long));
                    700:          if (val == 0)
                    701:            printf ("0");
                    702:          else
                    703:            printf ("0x%08x  %d", val, val);
                    704:        }
                    705: 
                    706:       /* If register has different raw and virtual formats,
                    707:         print the raw format in hex now.  */
                    708: 
                    709:       if (REGISTER_CONVERTIBLE (i))
                    710:        {
                    711:          register int j;
                    712: 
                    713:          printf ("  (raw 0x");
                    714:          for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
                    715:            printf ("%02x", raw_buffer[j]);
                    716:          printf (")");
                    717:        }
                    718:       printf ("\n");
                    719:     }
                    720: 
                    721:   printf ("Contents are relative to selected stack frame.\n");
                    722: }
                    723: 
1.1.1.2   root      724: #ifdef ATTACH_DETACH
                    725: /*
                    726:  * TODO:
                    727:  * Should save/restore the tty state since it might be that the
                    728:  * program to be debugged was started on this tty and it wants
                    729:  * the tty in some state other than what we want.  If it's running
                    730:  * on another terminal or without a terminal, then saving and
                    731:  * restoring the tty state is a harmless no-op.
                    732:  */
                    733: 
                    734: /*
                    735:  * attach_command --
                    736:  * takes a program started up outside of gdb and ``attaches'' to it.
1.1.1.3   root      737:  * This stops it cold in its tracks and allows us to start tracing it.
                    738:  * For this to work, we must be able to send the process a
1.1.1.2   root      739:  * signal and we must have the same effective uid as the program.
                    740:  */
                    741: static void
                    742: attach_command (args, from_tty)
                    743:      char *args;
                    744:      int from_tty;
                    745: {
                    746:   char *exec_file;
                    747:   int pid;
1.1.1.4   root      748:   int remote = 0;
1.1.1.2   root      749: 
                    750:   dont_repeat();
                    751: 
                    752:   if (!args)
                    753:     error_no_arg ("process-id to attach");
1.1.1.3   root      754: 
                    755:   while (*args == ' ' || *args == '\t') args++;
                    756: 
                    757:   if (args[0] == '/')
                    758:     remote = 1;
1.1.1.2   root      759:   else
                    760:     pid = atoi (args);
                    761: 
                    762:   if (inferior_pid)
                    763:     {
                    764:       if (query ("A program is being debugged already.  Kill it? "))
                    765:        kill_inferior ();
                    766:       else
                    767:        error ("Inferior not killed.");
                    768:     }
                    769: 
1.1.1.4   root      770:   exec_file = (char *) get_exec_file (1);
1.1.1.2   root      771: 
                    772:   if (from_tty)
                    773:     {
1.1.1.3   root      774:       if (remote)
                    775:        printf ("Attaching remote machine\n");
                    776:       else
                    777:        printf ("Attaching program: %s pid %d\n",
                    778:                exec_file, pid);
1.1.1.2   root      779:       fflush (stdout);
                    780:     }
                    781: 
1.1.1.3   root      782:   if (remote)
                    783:     {
                    784:       remote_open (args, from_tty);
                    785:       start_remote ();
                    786:     }
                    787:   else
                    788:     attach_program (pid);
1.1.1.2   root      789: }
                    790: 
                    791: /*
                    792:  * detach_command --
                    793:  * takes a program previously attached to and detaches it.
                    794:  * The program resumes execution and will no longer stop
                    795:  * on signals, etc.  We better not have left any breakpoints
                    796:  * in the program or it'll die when it hits one.  For this
                    797:  * to work, it may be necessary for the process to have been
                    798:  * previously attached.  It *might* work if the program was
                    799:  * started via the normal ptrace (PTRACE_TRACEME).
                    800:  */
                    801: 
                    802: static void
                    803: detach_command (args, from_tty)
                    804:      char *args;
                    805:      int from_tty;
                    806: {
                    807:   int signal = 0;
                    808: 
                    809:   if (!inferior_pid)
                    810:     error ("Not currently tracing a program\n");
                    811:   if (from_tty)
                    812:     {
1.1.1.4   root      813:       char *exec_file = (char *)get_exec_file (0);
                    814:       if (exec_file == 0)
                    815:        exec_file = "";
1.1.1.2   root      816:       printf ("Detaching program: %s pid %d\n",
                    817:              exec_file, inferior_pid);
                    818:       fflush (stdout);
                    819:     }
                    820:   if (args)
                    821:     signal = atoi (args);
                    822: 
                    823:   detach (signal);
                    824:   inferior_pid = 0;
                    825: }
                    826: #endif /* ATTACH_DETACH */
                    827: 
1.1       root      828: static
                    829: initialize ()
                    830: {
1.1.1.2   root      831:   add_com ("tty", class_run, tty_command,
                    832:           "Set terminal for future runs of program being debugged.");
                    833: 
1.1       root      834:   add_com ("set-args", class_run, set_args_command,
                    835:           "Specify arguments to give program being debugged when it is started.\n\
                    836: Follow this command with any number of args, to be passed to the program.");
                    837: 
                    838:   add_info ("environment", environment_info,
                    839:            "The environment to give the program, or one variable's value.\n\
                    840: With an argument VAR, prints the value of environment variable VAR to\n\
                    841: give the program being debugged.  With no arguments, prints the entire\n\
                    842: environment to be given to the program.");
                    843: 
                    844:   add_com ("unset-environment", class_run, unset_environment_command,
                    845:           "Cancel environment variable VAR for the program.\n\
                    846: This does not affect the program until the next \"run\" command.");
                    847:   add_com ("set-environment", class_run, set_environment_command,
                    848:           "Set environment variable value to give the program.\n\
                    849: Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
                    850: VALUES of environment variables are uninterpreted strings.\n\
                    851: This does not affect the program until the next \"run\" command.");
1.1.1.2   root      852:  
                    853: #ifdef ATTACH_DETACH
                    854:  add_com ("attach", class_run, attach_command,
                    855:           "Attach to a process that was started up outside of GDB.\n\
                    856: To do this, you must have permission to send the process a signal.\n\
                    857: And it must have the same effective uid as the debugger.\n\n\
                    858: Before using \"attach\", you must use the \"exec-file\" command\n\
                    859: to specify the program running in the process,\n\
                    860: and the \"symbol-file\" command to load its symbol table.");
                    861:   add_com ("detach", class_run, detach_command,
                    862:           "Detach the process previously attached.\n\
                    863: The process is no longer traced and continues its execution.");
                    864: #endif /* ATTACH_DETACH */
1.1       root      865: 
                    866:   add_com ("signal", class_run, signal_command,
                    867:           "Continue program giving it signal number SIGNUMBER.");
                    868: 
                    869:   add_com ("stepi", class_run, stepi_command,
                    870:           "Step one instruction exactly.\n\
                    871: Argument N means do this N times (or till program stops for another reason).");
                    872:   add_com_alias ("si", "stepi", class_alias, 0);
                    873: 
                    874:   add_com ("nexti", class_run, nexti_command,
                    875:           "Step one instruction, but proceed through subroutine calls.\n\
                    876: Argument N means do this N times (or till program stops for another reason).");
                    877:   add_com_alias ("ni", "nexti", class_alias, 0);
                    878: 
                    879:   add_com ("finish", class_run, finish_command,
                    880:           "Execute until selected stack frame returns.\n\
                    881: Upon return, the value returned is printed and put in the value history.");
                    882: 
                    883:   add_com ("next", class_run, next_command,
                    884:           "Step program, proceeding through subroutine calls.\n\
                    885: Like the \"step\" command as long as subroutine calls do not happen;\n\
                    886: when they do, the call is treated as one instruction.\n\
                    887: Argument N means do this N times (or till program stops for another reason).");
                    888:   add_com_alias ("n", "next", class_run, 1);
                    889: 
                    890:   add_com ("step", class_run, step_command,
                    891:           "Step program until it reaches a different source line.\n\
                    892: Argument N means do this N times (or till program stops for another reason).");
                    893:   add_com_alias ("s", "step", class_run, 1);
                    894: 
                    895:   add_com ("jump", class_run, jump_command,
                    896:           "Continue program being debugged at specified line or address.\n\
                    897: Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
                    898: for an address to start at.");
                    899: 
                    900:   add_com ("cont", class_run, cont_command,
                    901:           "Continue program being debugged, after signal or breakpoint.\n\
                    902: If proceeding from breakpoint, a number N may be used as an argument:\n\
                    903: then the same breakpoint won't break until the Nth time it is reached.");
                    904:   add_com_alias ("c", "cont", class_run, 1);
                    905: 
                    906:   add_com ("run", class_run, run_command,
                    907:           "Start debugged program.  You may specify arguments to give it.\n\
                    908: Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
                    909: Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
                    910: With no arguments, uses arguments last specified (with \"run\" or \"set-args\".\n\
                    911: To cancel previous arguments and run with no arguments,\n\
                    912: use \"set-args\" without arguments.");
                    913:   add_com_alias ("r", "run", class_run, 1);
                    914: 
                    915:   add_info ("registers", registers_info,
                    916:            "List of registers and their contents, for selected stack frame.\n\
                    917: Register name as argument means describe only that register.");
                    918: 
                    919:   add_info ("program", program_info,
                    920:            "Execution status of the program.");
                    921: 
                    922:   inferior_args = savestring (" ", 1); /* By default, no args.  */
                    923:   inferior_environ = make_environ ();
                    924:   init_environ (inferior_environ);
                    925: }
                    926: 
                    927: END_FILE

unix.superglobalmegacorp.com