2002-12-06 Andrew Cagney <ac131313@redhat.com>
[deliverable/binutils-gdb.git] / gdb / infcmd.c
index 5359e290e7b59b316220b79a03bba18654c76340..c8b5aa28e82dd182347f45774d48a5b80c5dbaa9 100644 (file)
@@ -41,6 +41,8 @@
 #include "event-top.h"
 #include "parser-defs.h"
 #include "regcache.h"
+#include "reggroups.h"
+#include <ctype.h>
 
 /* Functions exported for general use, in inferior.h: */
 
@@ -180,7 +182,7 @@ CORE_ADDR step_range_end;   /* Exclusive */
    This is how we know when we step into a subroutine call,
    and how to set the frame for the breakpoint used to step out.  */
 
-CORE_ADDR step_frame_address;
+struct frame_id step_frame_id;
 
 /* Our notion of the current stack pointer.  */
 
@@ -276,7 +278,7 @@ construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
 
       /* We over-compute the size.  It shouldn't matter.  */
       for (i = 0; i < argc; ++i)
-       length += 2 * strlen (argv[i]) + 1;
+       length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
 
       result = (char *) xmalloc (length);
       out = result;
@@ -286,11 +288,20 @@ construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
          if (i > 0)
            *out++ = ' ';
 
-         for (cp = argv[i]; *cp; ++cp)
+         /* Need to handle empty arguments specially.  */
+         if (argv[i][0] == '\0')
            {
-             if (strchr (special, *cp) != NULL)
-               *out++ = '\\';
-             *out++ = *cp;
+             *out++ = '\'';
+             *out++ = '\'';
+           }
+         else
+           {
+             for (cp = argv[i]; *cp; ++cp)
+               {
+                 if (strchr (special, *cp) != NULL)
+                   *out++ = '\\';
+                 *out++ = *cp;
+               }
            }
        }
       *out = '\0';
@@ -616,7 +627,7 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
          frame = get_current_frame ();
          if (!frame)           /* Avoid coredump here.  Why tho? */
            error ("No current frame");
-         step_frame_address = FRAME_FP (frame);
+         step_frame_id = get_frame_id (frame);
          step_sp = read_sp ();
 
          if (!single_inst)
@@ -731,7 +742,7 @@ step_once (int skip_subroutines, int single_inst, int count)
       frame = get_current_frame ();
       if (!frame)              /* Avoid coredump here.  Why tho? */
        error ("No current frame");
-      step_frame_address = FRAME_FP (frame);
+      step_frame_id = get_frame_id (frame);
       step_sp = read_sp ();
 
       if (!single_inst)
@@ -1007,8 +1018,11 @@ run_stack_dummy (CORE_ADDR addr, struct regcache *buffer)
 
          addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
          so we need to subtract the CALL_DUMMY_START_OFFSET.  */
+      /* FIXME: cagney/2002-12-01: Rather than pass in curent frame,
+         why not just create, and then pass in a frame ID.  This would
+         make it possible to eliminate set_current_frame().  */
       bpt = set_momentary_breakpoint (sal,
-                                     get_current_frame (),
+                                     get_frame_id (get_current_frame ()),
                                      bp_call_dummy);
       bpt->disposition = disp_del;
 
@@ -1094,7 +1108,7 @@ until_next_command (int from_tty)
     }
 
   step_over_calls = STEP_OVER_ALL;
-  step_frame_address = FRAME_FP (frame);
+  step_frame_id = get_frame_id (frame);
   step_sp = read_sp ();
 
   step_multi = 0;              /* Only one call to proceed */
@@ -1261,19 +1275,19 @@ finish_command (char *arg, int from_tty)
     error ("The \"finish\" command does not take any arguments.");
   if (!target_has_execution)
     error ("The program is not running.");
-  if (selected_frame == NULL)
+  if (deprecated_selected_frame == NULL)
     error ("No selected frame.");
 
-  frame = get_prev_frame (selected_frame);
+  frame = get_prev_frame (deprecated_selected_frame);
   if (frame == 0)
     error ("\"finish\" not meaningful in the outermost frame.");
 
   clear_proceed_status ();
 
-  sal = find_pc_line (frame->pc, 0);
-  sal.pc = frame->pc;
+  sal = find_pc_line (get_frame_pc (frame), 0);
+  sal.pc = get_frame_pc (frame);
 
-  breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
+  breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
 
   if (!event_loop_p || !target_can_async_p ())
     old_chain = make_cleanup_delete_breakpoint (breakpoint);
@@ -1282,15 +1296,15 @@ finish_command (char *arg, int from_tty)
 
   /* Find the function we will return from.  */
 
-  function = find_pc_function (selected_frame->pc);
+  function = find_pc_function (get_frame_pc (deprecated_selected_frame));
 
   /* Print info on the selected frame, including level number
      but not source.  */
   if (from_tty)
     {
       printf_filtered ("Run till exit from ");
-      print_stack_frame (selected_frame,
-                        frame_relative_level (selected_frame), 0);
+      print_stack_frame (deprecated_selected_frame,
+                        frame_relative_level (deprecated_selected_frame), 0);
     }
 
   /* If running asynchronously and the target support asynchronous
@@ -1571,10 +1585,9 @@ default_print_registers_info (struct gdbarch *gdbarch,
   char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
   char *virtual_buffer = alloca (MAX_REGISTER_VIRTUAL_SIZE);
 
-  /* FIXME: cagney/2002-03-08: This should be deprecated.  */
-  if (DO_REGISTERS_INFO_P ())
+  if (DEPRECATED_DO_REGISTERS_INFO_P ())
     {
-      DO_REGISTERS_INFO (regnum, print_all);
+      DEPRECATED_DO_REGISTERS_INFO (regnum, print_all);
       return;
     }
 
@@ -1584,11 +1597,14 @@ default_print_registers_info (struct gdbarch *gdbarch,
          specific reg.  */
       if (regnum == -1)
        {
-         if (!print_all)
+         if (print_all)
            {
-             if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
+             if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
                continue;
-             if (TYPE_VECTOR (REGISTER_VIRTUAL_TYPE (i)))
+           }
+         else
+           {
+             if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
                continue;
            }
        }
@@ -1664,12 +1680,6 @@ default_print_registers_info (struct gdbarch *gdbarch,
            }
        }
 
-      /* The SPARC wants to print even-numbered float regs as doubles
-         in addition to printing them as floats.  */
-#ifdef PRINT_REGISTER_HOOK
-      PRINT_REGISTER_HOOK (i);
-#endif
-
       fprintf_filtered (file, "\n");
     }
 }
@@ -1682,45 +1692,99 @@ registers_info (char *addr_exp, int fpregs)
 
   if (!target_has_registers)
     error ("The program has no registers now.");
-  if (selected_frame == NULL)
+  if (deprecated_selected_frame == NULL)
     error ("No selected frame.");
 
   if (!addr_exp)
     {
       gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
-                                   selected_frame, -1, fpregs);
+                                   deprecated_selected_frame, -1, fpregs);
       return;
     }
 
-  do
+  while (*addr_exp != '\0')
     {
-      if (addr_exp[0] == '$')
-       addr_exp++;
-      end = addr_exp;
-      while (*end != '\0' && *end != ' ' && *end != '\t')
-       ++end;
-      numregs = NUM_REGS + NUM_PSEUDO_REGS;
-
-      regnum = frame_map_name_to_regnum (addr_exp, end - addr_exp);
-      if (regnum >= 0)
-       goto found;
+      char *start;
+      const char *end;
 
-      regnum = numregs;
+      /* Keep skipping leading white space.  */
+      if (isspace ((*addr_exp)))
+       {
+         addr_exp++;
+         continue;
+       }
 
-      if (*addr_exp >= '0' && *addr_exp <= '9')
-       regnum = atoi (addr_exp);       /* Take a number */
-      if (regnum >= numregs)   /* Bad name, or bad number */
-       error ("%.*s: invalid register", (int) (end - addr_exp), addr_exp);
+      /* Discard any leading ``$''.  Check that there is something
+         resembling a register following it.  */
+      if (addr_exp[0] == '$')
+       addr_exp++;
+      if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
+       error ("Missing register name");
 
-    found:
-      gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
-                                   selected_frame, regnum, fpregs);
+      /* Find the start/end of this register name/num/group.  */
+      start = addr_exp;
+      while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
+       addr_exp++;
+      end = addr_exp;
+      
+      /* Figure out what we've found and display it.  */
+
+      /* A register name?  */
+      {
+       int regnum = frame_map_name_to_regnum (start, end - start);
+       if (regnum >= 0)
+         {
+           gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
+                                         deprecated_selected_frame, regnum, fpregs);
+           continue;
+         }
+      }
+       
+      /* A register number?  (how portable is this one?).  */
+      {
+       char *endptr;
+       int regnum = strtol (start, &endptr, 0);
+       if (endptr == end
+           && regnum >= 0
+           && regnum < NUM_REGS + NUM_PSEUDO_REGS)
+         {
+           gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
+                                         deprecated_selected_frame, regnum, fpregs);
+           continue;
+         }
+      }
+
+      /* A register group?  */
+      {
+       struct reggroup *const *group;
+       for (group = reggroups (current_gdbarch);
+            (*group) != NULL;
+            group++)
+         {
+           /* Don't bother with a length check.  Should the user
+              enter a short register group name, go with the first
+              group that matches.  */
+           if (strncmp (start, reggroup_name ((*group)), end - start) == 0)
+             break;
+         }
+       if ((*group) != NULL)
+         {
+           int regnum;
+           for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
+             {
+               if (gdbarch_register_reggroup_p (current_gdbarch, regnum,
+                                                (*group)))
+                 gdbarch_print_registers_info (current_gdbarch,
+                                               gdb_stdout, deprecated_selected_frame,
+                                               regnum, fpregs);
+             }
+           continue;
+         }
+      }
 
-      addr_exp = end;
-      while (*addr_exp == ' ' || *addr_exp == '\t')
-       ++addr_exp;
+      /* Nothing matched.  */
+      error ("Invalid register `%.*s'", (int) (end - start), start);
     }
-  while (*addr_exp != '\0');
 }
 
 void
@@ -1739,6 +1803,11 @@ static void
 print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
                   struct frame_info *frame, const char *args)
 {
+  if (!target_has_registers)
+    error ("The program has no registers now.");
+  if (deprecated_selected_frame == NULL)
+    error ("No selected frame.");
+
   if (gdbarch_print_vector_info_p (gdbarch))
     gdbarch_print_vector_info (gdbarch, file, frame, args);
   else
@@ -1746,14 +1815,9 @@ print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
       int regnum;
       int printed_something = 0;
 
-      if (!target_has_registers)
-       error ("The program has no registers now.");
-      if (selected_frame == NULL)
-       error ("No selected frame.");
-
       for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
        {
-         if (TYPE_VECTOR (REGISTER_VIRTUAL_TYPE (regnum)))
+         if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
            {
              printed_something = 1;
              gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
@@ -1767,7 +1831,7 @@ print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
 static void
 vector_info (char *args, int from_tty)
 {
-  print_vector_info (current_gdbarch, gdb_stdout, selected_frame, args);
+  print_vector_info (current_gdbarch, gdb_stdout, deprecated_selected_frame, args);
 }
 \f
 
@@ -1906,6 +1970,11 @@ static void
 print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
                  struct frame_info *frame, const char *args)
 {
+  if (!target_has_registers)
+    error ("The program has no registers now.");
+  if (deprecated_selected_frame == NULL)
+    error ("No selected frame.");
+
   if (gdbarch_print_float_info_p (gdbarch))
     gdbarch_print_float_info (gdbarch, file, frame, args);
   else
@@ -1919,14 +1988,9 @@ print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
       int regnum;
       int printed_something = 0;
 
-      if (!target_has_registers)
-       error ("The program has no registers now.");
-      if (selected_frame == NULL)
-       error ("No selected frame.");
-
       for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
        {
-         if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
+         if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
            {
              printed_something = 1;
              gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
@@ -1942,7 +2006,7 @@ No floating-point info available for this processor.\n");
 static void
 float_info (char *args, int from_tty)
 {
-  print_float_info (current_gdbarch, gdb_stdout, selected_frame, args);
+  print_float_info (current_gdbarch, gdb_stdout, deprecated_selected_frame, args);
 }
 \f
 /* ARGSUSED */
This page took 0.032561 seconds and 4 git commands to generate.