* mipsread.c: Clean up some white space.
[deliverable/binutils-gdb.git] / gdb / infcmd.c
index f387ba0308cbe3c668a96e27374489eaaaab52d1..8f5ba51c7923f2cbdc5f78360d59b6406a956d3d 100644 (file)
@@ -1,29 +1,28 @@
-/* Memory-access and commands for inferior process, for GDB.
-   Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc.
+/* Memory-access and commands for "inferior" (child) process, for GDB.
+   Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
-GDB is free software; you can redistribute it and/or modify
+This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
-any later version.
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-GDB is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GDB; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-#include <stdio.h>
+#include "defs.h"
 #include <signal.h>
 #include <sys/param.h>
 #include <string.h>
-#include "defs.h"
-#include "param.h"
 #include "symtab.h"
+#include "gdbtypes.h"
 #include "frame.h"
 #include "inferior.h"
 #include "environ.h"
@@ -32,9 +31,80 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "gdbcore.h"
 #include "target.h"
 
-extern char *sys_siglist[];
+static void
+continue_command PARAMS ((char *, int));
+
+static void
+until_next_command PARAMS ((int));
+
+static void 
+until_command PARAMS ((char *, int));
+
+static void
+path_info PARAMS ((char *, int));
+
+static void
+path_command PARAMS ((char *, int));
+
+static void
+unset_command PARAMS ((char *, int));
+
+static void
+float_info PARAMS ((char *, int));
+
+static void
+detach_command PARAMS ((char *, int));
 
-extern void until_break_command ();    /* breakpoint.c */
+static void
+nofp_registers_info PARAMS ((char *, int));
+
+static void
+all_registers_info PARAMS ((char *, int));
+
+static void
+registers_info PARAMS ((char *, int));
+
+static void
+do_registers_info PARAMS ((int, int));
+
+static void
+unset_environment_command PARAMS ((char *, int));
+
+static void
+set_environment_command PARAMS ((char *, int));
+
+static void
+environment_info PARAMS ((char *, int));
+
+static void
+program_info PARAMS ((char *, int));
+
+static void
+finish_command PARAMS ((char *, int));
+
+static void
+signal_command PARAMS ((char *, int));
+
+static void
+jump_command PARAMS ((char *, int));
+
+static void
+step_1 PARAMS ((int, int, char *));
+
+static void
+nexti_command PARAMS ((char *, int));
+
+static void
+stepi_command PARAMS ((char *, int));
+
+static void
+next_command PARAMS ((char *, int));
+
+static void
+step_command PARAMS ((char *, int));
+
+static void
+run_command PARAMS ((char *, int));
 
 #define ERROR_NO_INFERIOR \
    if (!target_has_execution) error ("The program is not being run.");
@@ -118,9 +188,6 @@ int step_multi;
 
 struct environ *inferior_environ;
 
-CORE_ADDR read_pc ();
-void breakpoint_clear_ignore_counts ();
-
 \f
 /* ARGSUSED */
 void
@@ -149,26 +216,26 @@ run_command (args, from_tty)
          !query ("The program being debugged has been started already.\n\
 Start it from the beginning? "))
        error ("Program not restarted.");
-      target_kill ((char *)0, 0);
+      target_kill ();
     }
 
   exec_file = (char *) get_exec_file (0);
 
-  /* The exec file is re-read every time we do an inferior_died, so
+  /* The exec file is re-read every time we do a generic_mourn_inferior, so
      we just have to worry about the symbol file.  */
   reread_symbols ();
 
   if (args)
     {
       char *cmd;
-      cmd = concat ("set args ", args, "");
+      cmd = concat ("set args ", args, NULL);
       make_cleanup (free, cmd);
       execute_command (cmd, from_tty);
     }
 
   if (from_tty)
     {
-      printf ("Starting program: %s %s\n",
+      printf_filtered ("Starting program: %s %s\n",
              exec_file? exec_file: "", inferior_args);
       fflush (stdout);
     }
@@ -177,7 +244,7 @@ Start it from the beginning? "))
                          environ_vector (inferior_environ));
 }
 \f
-void
+static void
 continue_command (proc_count_exp, from_tty)
      char *proc_count_exp;
      int from_tty;
@@ -203,13 +270,13 @@ continue_command (proc_count_exp, from_tty)
          /* set_ignore_count prints a message ending with a period.
             So print two spaces before "Continuing.".  */
          if (from_tty)
-           printf ("  ");
+           printf_filtered ("  ");
          num = bpstat_num (&bs);
        }
     }
 
   if (from_tty)
-    printf ("Continuing.\n");
+    printf_filtered ("Continuing.\n");
 
   clear_proceed_status ();
 
@@ -217,12 +284,11 @@ continue_command (proc_count_exp, from_tty)
 }
 \f
 /* Step until outside of current statement.  */
-static void step_1 ();
 
 /* ARGSUSED */
 static void
 step_command (count_string, from_tty)
-     char * count_string;
+     char *count_string;
      int from_tty;
 {
   step_1 (0, 0, count_string);
@@ -233,7 +299,7 @@ step_command (count_string, from_tty)
 /* ARGSUSED */
 static void
 next_command (count_string, from_tty)
-     char * count_string;
+     char *count_string;
      int from_tty;
 {
   step_1 (1, 0, count_string);
@@ -244,7 +310,7 @@ next_command (count_string, from_tty)
 /* ARGSUSED */
 static void
 stepi_command (count_string, from_tty)
-     char * count_string;
+     char *count_string;
      int from_tty;
 {
   step_1 (0, 1, count_string);
@@ -253,7 +319,7 @@ stepi_command (count_string, from_tty)
 /* ARGSUSED */
 static void
 nexti_command (count_string, from_tty)
-     char * count_string;
+     char *count_string;
      int from_tty;
 {
   step_1 (1, 1, count_string);
@@ -267,15 +333,21 @@ step_1 (skip_subroutines, single_inst, count_string)
 {
   register int count = 1;
   FRAME fr;
+  struct cleanup *cleanups = 0;
 
   ERROR_NO_INFERIOR;
   count = count_string ? parse_and_eval_address (count_string) : 1;
 
+  if (!single_inst || skip_subroutines) /* leave si command alone */
+    {
+      enable_longjmp_breakpoint();
+      cleanups = make_cleanup(disable_longjmp_breakpoint, 0);
+    }
+
   for (; count > 0; count--)
     {
       clear_proceed_status ();
 
-
       fr = get_current_frame ();
       if (!fr)                         /* Avoid coredump here.  Why tho? */
        error ("No current frame");
@@ -286,22 +358,22 @@ step_1 (skip_subroutines, single_inst, count_string)
          find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
          if (step_range_end == 0)
            {
-             int misc;
+             struct minimal_symbol *msymbol;
 
-             misc = find_pc_misc_function (stop_pc);
+             msymbol = lookup_minimal_symbol_by_pc (stop_pc);
              target_terminal_ours ();
-             printf ("Current function has no line number information.\n");
+             printf_filtered ("Current function has no line number information.\n");
              fflush (stdout);
 
              /* No info or after _etext ("Can't happen") */
-             if (misc == -1 || misc == misc_function_count - 1)
+             if (msymbol == NULL || (msymbol + 1) -> name == NULL)
                error ("No data available on pc function.");
 
-             printf ("Single stepping until function exit.\n");
+             printf_filtered ("Single stepping until function exit.\n");
              fflush (stdout);
 
-             step_range_start = misc_function_vector[misc].address;
-             step_range_end = misc_function_vector[misc + 1].address;
+             step_range_start = msymbol -> address;
+             step_range_end = (msymbol + 1) -> address;
            }
        }
       else
@@ -326,6 +398,9 @@ step_1 (skip_subroutines, single_inst, count_string)
       write_register (NPC_REGNUM, read_register (PC_REGNUM));
 #endif
     }
+
+  if (!single_inst || skip_subroutines)
+    do_cleanups(cleanups);
 }
 \f
 /* Continue program at specified address.  */
@@ -338,6 +413,10 @@ jump_command (arg, from_tty)
   register CORE_ADDR addr;
   struct symtabs_and_lines sals;
   struct symtab_and_line sal;
+  struct symbol *fn;
+  struct symbol *sfn;
+  char *fname;
+  struct cleanup *back_to;
 
   ERROR_NO_INFERIOR;
 
@@ -351,30 +430,32 @@ jump_command (arg, from_tty)
     }
 
   sal = sals.sals[0];
-  free (sals.sals);
+  free ((PTR)sals.sals);
 
   if (sal.symtab == 0 && sal.pc == 0)
     error ("No source file has been specified.");
 
-  if (sal.pc == 0)
-    sal.pc = find_line_pc (sal.symtab, sal.line);
+  resolve_sal_pc (&sal);                       /* May error out */
 
-  {
-    struct symbol *fn = get_frame_function (get_current_frame ());
-    struct symbol *sfn = find_pc_function (sal.pc);
-    if (fn != 0 && sfn != fn
-       && ! query ("Line %d is not in `%s'.  Jump anyway? ",
-                   sal.line, SYMBOL_NAME (fn)))
-      error ("Not confirmed.");
-  }
-
-  if (sal.pc == 0)
-    error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename);
+  /* See if we are trying to jump to another function. */
+  fn = get_frame_function (get_current_frame ());
+  sfn = find_pc_function (sal.pc);
+  if (fn != NULL && sfn != fn)
+    {
+      fname = strdup_demangled (SYMBOL_NAME (fn));
+      back_to = make_cleanup (free, fname);
+      if (!query ("Line %d is not in `%s'.  Jump anyway? ", sal.line, fname))
+       {
+         error ("Not confirmed.");
+         /* NOTREACHED */
+       }
+      do_cleanups (back_to);
+    }
 
   addr = ADDR_BITS_SET (sal.pc);
 
   if (from_tty)
-    printf ("Continuing at 0x%x.\n", addr);
+    printf_filtered ("Continuing at %s.\n", local_hex_string(addr));
 
   clear_proceed_status ();
   proceed (addr, 0, 0);
@@ -398,7 +479,7 @@ signal_command (signum_exp, from_tty)
   signum = parse_and_eval_address (signum_exp);
 
   if (from_tty)
-    printf ("Continuing with signal %d.\n", signum);
+    printf_filtered ("Continuing with signal %d.\n", signum);
 
   clear_proceed_status ();
   proceed (stop_pc, signum, 0);
@@ -419,7 +500,7 @@ signal_command (signum_exp, from_tty)
    returns to its caller with that frame already gone.
    Otherwise, the caller never gets returned to.  */
 
-/* 4 => return instead of letting the stack dummy run.  */
+/* DEBUG HOOK:  4 => return instead of letting the stack dummy run.  */
 
 static int stack_dummy_testing = 0;
 
@@ -447,7 +528,7 @@ The expression which contained the function call has been discarded.");
 
   /* On return, the stack dummy has been popped already.  */
 
-  bcopy (stop_registers, buffer, sizeof stop_registers);
+  memcpy (buffer, stop_registers, sizeof stop_registers);
 }
 \f
 /* Proceed until we reach a different source line with pc greater than
@@ -459,7 +540,7 @@ The expression which contained the function call has been discarded.");
    of wait_for_inferior and the proceed status code. -- randy */
 
 /* ARGSUSED */
-void
+static void
 until_next_command (from_tty)
      int from_tty;
 {
@@ -481,12 +562,12 @@ until_next_command (from_tty)
   
   if (!func)
     {
-      int misc_func = find_pc_misc_function (pc);
+      struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
       
-      if (misc_func != -1)
+      if (msymbol == NULL)
        error ("Execution is not within a known function.");
       
-      step_range_start = misc_function_vector[misc_func].address;
+      step_range_start = msymbol -> address;
       step_range_end = pc;
     }
   else
@@ -505,7 +586,7 @@ until_next_command (from_tty)
   proceed ((CORE_ADDR) -1, -1, 1);
 }
 
-void 
+static void 
 until_command (arg, from_tty)
      char *arg;
      int from_tty;
@@ -530,6 +611,8 @@ finish_command (arg, from_tty)
   register FRAME frame;
   struct frame_info *fi;
   register struct symbol *function;
+  struct breakpoint *breakpoint;
+  struct cleanup *old_chain;
 
   if (arg)
     error ("The \"finish\" command does not take any arguments.");
@@ -547,23 +630,30 @@ finish_command (arg, from_tty)
   fi = get_frame_info (frame);
   sal = find_pc_line (fi->pc, 0);
   sal.pc = fi->pc;
-  set_momentary_breakpoint (sal, frame);
+
+  breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
+
+  old_chain = make_cleanup(delete_breakpoint, breakpoint);
 
   /* Find the function we will return from.  */
 
   fi = get_frame_info (selected_frame);
   function = find_pc_function (fi->pc);
 
+  /* Print info on the selected frame, including level number
+     but not source.  */
   if (from_tty)
     {
-      printf ("Run till exit from ");
-      print_selected_frame ();
+      printf_filtered ("Run till exit from ");
+      print_stack_frame (selected_frame, selected_frame_level, 0);
     }
 
   proceed_to_finish = 1;               /* We want stop_registers, please... */
   proceed ((CORE_ADDR) -1, -1, 0);
 
-  if (bpstat_momentary_breakpoint (stop_bpstat) && function != 0)
+  /* Did we stop at our breakpoint? */
+  if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
+      && function != 0)
     {
       struct type *value_type;
       register value val;
@@ -584,10 +674,11 @@ finish_command (arg, from_tty)
                                   value_type,
                BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
 
-      printf ("Value returned is $%d = ", record_latest_value (val));
+      printf_filtered ("Value returned is $%d = ", record_latest_value (val));
       value_print (val, stdout, 0, Val_no_prettyprint);
-      putchar ('\n');
+      printf_filtered ("\n");
     }
+  do_cleanups(old_chain);
 }
 \f
 /* ARGSUSED */
@@ -601,14 +692,14 @@ program_info (args, from_tty)
   
   if (!target_has_execution)
     {
-      printf ("The program being debugged is not being run.\n");
+      printf_filtered ("The program being debugged is not being run.\n");
       return;
     }
 
   target_files_info ();
-  printf ("Program stopped at 0x%x.\n", stop_pc);
+  printf_filtered ("Program stopped at %s.\n", local_hex_string(stop_pc));
   if (stop_step)
-    printf ("It stopped after being stepped.\n");
+    printf_filtered ("It stopped after being stepped.\n");
   else if (num != 0)
     {
       /* There may be several breakpoints in the same place, so this
@@ -616,9 +707,9 @@ program_info (args, from_tty)
       while (num != 0)
        {
          if (num < 0)
-           printf ("It stopped at a breakpoint that has since been deleted.\n");
+           printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
          else
-           printf ("It stopped at breakpoint %d.\n", num);
+           printf_filtered ("It stopped at breakpoint %d.\n", num);
          num = bpstat_num (&bs);
        }
     }
@@ -626,39 +717,40 @@ program_info (args, from_tty)
 #ifdef PRINT_RANDOM_SIGNAL
     PRINT_RANDOM_SIGNAL (stop_signal);
 #else
-    printf ("It stopped with signal %d (%s).\n",
-           stop_signal, 
-           (stop_signal > NSIG)? "unknown": sys_siglist[stop_signal]);
+    printf_filtered ("It stopped with signal %d (%s).\n",
+                    stop_signal, safe_strsignal (stop_signal));
 #endif
   }
 
   if (!from_tty)
-    printf ("Type \"info stack\" or \"info registers\" for more information.\n");
+    printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
 }
 \f
 static void
-environment_info (var)
+environment_info (var, from_tty)
      char *var;
+     int from_tty;
 {
   if (var)
     {
       register char *val = get_in_environ (inferior_environ, var);
       if (val)
-       printf ("%s = %s\n", var, val);
+       printf_filtered ("%s = %s\n", var, val);
       else
-       printf ("Environment variable \"%s\" not defined.\n", var);
+       printf_filtered ("Environment variable \"%s\" not defined.\n", var);
     }
   else
     {
       register char **vector = environ_vector (inferior_environ);
       while (*vector)
-       printf ("%s\n", *vector++);
+       printf_filtered ("%s\n", *vector++);
     }
 }
 
 static void
-set_environment_command (arg)
+set_environment_command (arg, from_tty)
      char *arg;
+     int from_tty;
 {
   register char *p, *val, *var;
   int nullset = 0;
@@ -708,7 +800,7 @@ set_environment_command (arg)
   var = savestring (arg, p - arg);
   if (nullset)
     {
-      printf ("Setting environment variable \"%s\" to null value.\n", var);
+      printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
       set_in_environ (inferior_environ, var, "");
     }
   else
@@ -740,18 +832,18 @@ unset_environment_command (var, from_tty)
 const static char path_var_name[] = "PATH";
 
 /* ARGSUSED */
-void
+static void
 path_info (args, from_tty)
      char *args;
      int from_tty;
 {
-  printf ("Executable and object file path: %s\n", 
+  printf_filtered ("Executable and object file path: %s\n", 
       get_in_environ (inferior_environ, path_var_name));
 }
 
 /* Add zero or more directories to the front of the execution path.  */
 
-void
+static void
 path_command (dirname, from_tty)
      char *dirname;
      int from_tty;
@@ -784,34 +876,41 @@ write_pc (val)
   pc_changed = 0;
 }
 
-char *reg_names[] = REGISTER_NAMES;
+const char * const reg_names[] = REGISTER_NAMES;
 
 /* Print out the machine register regnum. If regnum is -1,
-   print all registers.
+   print all registers (fpregs == 1) or all non-float registers
+   (fpregs == 0).
+
    For most machines, having all_registers_info() print the
    register(s) one per line is good enough. If a different format
-   is required, (eg, for SPARC or Pyramid 90x, which both have
+   is required, (eg, for MIPS or Pyramid 90x, which both have
    lots of regs), or there is an existing convention for showing
-   all the registers, define the macro DO_REGISTERS_INFO(regnum)
+   all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
    to provide that format.  */  
+
 #if !defined (DO_REGISTERS_INFO)
-#define DO_REGISTERS_INFO(regnum) do_registers_info(regnum)
-static void do_registers_info (regnum)
+#define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
+static void
+do_registers_info (regnum, fpregs)
      int regnum;
+     int fpregs;
 {
   register int i;
 
-  if (regnum == -1)
-    printf_filtered (
-      "Register       Contents (relative to selected stack frame)\n\n");
-
   for (i = 0; i < NUM_REGS; i++)
     {
       char raw_buffer[MAX_REGISTER_RAW_SIZE];
       char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
 
-      if (regnum != -1 && i != regnum)
-       continue;
+      /* Decide between printing all regs, nonfloat regs, or specific reg.  */
+      if (regnum == -1) {
+       if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
+         continue;
+      } else {
+        if (i != regnum)
+         continue;
+      }
 
       fputs_filtered (reg_names[i], stdout);
       print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
@@ -873,8 +972,9 @@ static void do_registers_info (regnum)
 #endif /* no DO_REGISTERS_INFO.  */
 
 static void
-registers_info (addr_exp)
+registers_info (addr_exp, fpregs)
      char *addr_exp;
+     int fpregs;
 {
   int regnum;
 
@@ -900,7 +1000,23 @@ registers_info (addr_exp)
   else
     regnum = -1;
 
-  DO_REGISTERS_INFO(regnum);
+  DO_REGISTERS_INFO(regnum, fpregs);
+}
+
+static void
+all_registers_info (addr_exp, from_tty)
+     char *addr_exp;
+     int from_tty;
+{
+  registers_info (addr_exp, 1);
+}
+
+static void
+nofp_registers_info (addr_exp, from_tty)
+     char *addr_exp;
+     int from_tty;
+{
+  registers_info (addr_exp, 0);
 }
 \f
 /*
@@ -951,13 +1067,14 @@ detach_command (args, from_tty)
 
 /* ARGSUSED */
 static void
-float_info (addr_exp)
+float_info (addr_exp, from_tty)
      char *addr_exp;
+     int from_tty;
 {
 #ifdef FLOAT_INFO
        FLOAT_INFO;
 #else
-       printf ("No floating point info available for this processor.\n");
+       printf_filtered ("No floating point info available for this processor.\n");
 #endif
 }
 \f
@@ -969,7 +1086,7 @@ unset_command (args, from_tty)
      char *args;
      int from_tty;
 {
-  printf ("\"unset\" must be followed by the name of an unset subcommand.\n");
+  printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
   help_list (unsetlist, "unset ", -1, stdout);
 }
 
@@ -1022,12 +1139,13 @@ This path is equivalent to the $PATH shell variable.  It is a list of\n\
 directories, separated by colons.  These directories are searched to find\n\
 fully linked executable files and separately compiled object files as needed.");
 
-  add_info ("path", path_info,
+  c = add_cmd ("paths", no_class, path_info,
            "Current search path for finding object files.\n\
 $cwd in the path means the current working directory.\n\
 This path is equivalent to the $PATH shell variable.  It is a list of\n\
 directories, separated by colons.  These directories are searched to find\n\
-fully linked executable files and separately compiled object files as needed.");
+fully linked executable files and separately compiled object files as needed.", &showlist);
+  c->completer = noop_completer;
 
  add_com ("attach", class_run, attach_command,
           "Attach to a process or file outside of GDB.\n\
@@ -1095,13 +1213,17 @@ then the same breakpoint won't break until the Nth time it is reached.");
           "Start debugged program.  You may specify arguments to give it.\n\
 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
-With no arguments, uses arguments last specified (with \"run\" or \"set args\".\n\
+With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
 To cancel previous arguments and run with no arguments,\n\
 use \"set args\" without arguments.");
   add_com_alias ("r", "run", class_run, 1);
 
-  add_info ("registers", registers_info,
-           "List of registers and their contents, for selected stack frame.\n\
+  add_info ("registers", nofp_registers_info,
+    "List of integer registers and their contents, for selected stack frame.\n\
+Register name as argument means describe only that register.");
+
+  add_info ("all-registers", all_registers_info,
+"List of all registers and their contents, for selected stack frame.\n\
 Register name as argument means describe only that register.");
 
   add_info ("program", program_info,
This page took 0.032298 seconds and 4 git commands to generate.