2003-06-23 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
index c11c39cf949acdf6da6de9906b96751be4d2f77d..043600e98483ba6b694ad4bd059b98fc16e12025 100644 (file)
@@ -1,6 +1,6 @@
 /* Dynamic architecture support for GDB, the GNU debugger.
 
-   Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
+   Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
    Inc.
 
    This file is part of GDB.
 
 #include "floatformat.h"
 
-/* Use the program counter to determine the contents and size
-   of a breakpoint instruction.  If no target-dependent macro
-   BREAKPOINT_FROM_PC has been defined to implement this function,
-   assume that the breakpoint doesn't depend on the PC, and
-   use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
-   Return a pointer to a string of bytes that encode a breakpoint
-   instruction, stores the length of the string to *lenptr,
-   and optionally adjust the pc to point to the correct memory location
-   for inserting the breakpoint.  */
-
-const unsigned char *
-legacy_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
-{
-  /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
-     breakpoint.  On some machines, breakpoints are handled by the
-     target environment and we don't have to worry about them here.  */
-#ifdef BIG_BREAKPOINT
-  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
-    {
-      static unsigned char big_break_insn[] = BIG_BREAKPOINT;
-      *lenptr = sizeof (big_break_insn);
-      return big_break_insn;
-    }
-#endif
-#ifdef LITTLE_BREAKPOINT
-  if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
-    {
-      static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
-      *lenptr = sizeof (little_break_insn);
-      return little_break_insn;
-    }
-#endif
-#ifdef BREAKPOINT
-  {
-    static unsigned char break_insn[] = BREAKPOINT;
-    *lenptr = sizeof (break_insn);
-    return break_insn;
-  }
-#endif
-  *lenptr = 0;
-  return NULL;
-}
-
 /* Implementation of extract return value that grubs around in the
    register cache.  */
 void
 legacy_extract_return_value (struct type *type, struct regcache *regcache,
-                            char *valbuf)
+                            void *valbuf)
 {
   char *registers = deprecated_grub_regcache_for_registers (regcache);
-  DEPRECATED_EXTRACT_RETURN_VALUE (type, registers, valbuf);
+  bfd_byte *buf = valbuf;
+  DEPRECATED_EXTRACT_RETURN_VALUE (type, registers, buf); /* OK */
+}
+
+/* Implementation of store return value that grubs the register cache.
+   Takes a local copy of the buffer to avoid const problems.  */
+void
+legacy_store_return_value (struct type *type, struct regcache *regcache,
+                          const void *buf)
+{
+  bfd_byte *b = alloca (TYPE_LENGTH (type));
+  gdb_assert (regcache == current_regcache);
+  memcpy (b, buf, TYPE_LENGTH (type));
+  DEPRECATED_STORE_RETURN_VALUE (type, b);
+}
+
+
+int
+always_use_struct_convention (int gcc_p, struct type *value_type)
+{
+  return 1;
 }
 
+
 int
 legacy_register_sim_regno (int regnum)
 {
@@ -177,7 +155,9 @@ LONGEST legacy_call_dummy_words[1];
 int legacy_sizeof_call_dummy_words = sizeof (legacy_call_dummy_words);
 
 void
-generic_remote_translate_xfer_address (CORE_ADDR gdb_addr, int gdb_len,
+generic_remote_translate_xfer_address (struct gdbarch *gdbarch,
+                                      struct regcache *regcache,
+                                      CORE_ADDR gdb_addr, int gdb_len,
                                       CORE_ADDR * rem_addr, int *rem_len)
 {
   *rem_addr = gdb_addr;
@@ -195,7 +175,7 @@ generic_prologue_frameless_p (CORE_ADDR ip)
 int
 legacy_print_insn (bfd_vma vma, disassemble_info *info)
 {
-  return (*tm_print_insn) (vma, info);
+  return (*deprecated_tm_print_insn) (vma, info);
 }
 
 /* Helper functions for INNER_THAN */
@@ -259,14 +239,7 @@ default_double_format (struct gdbarch *gdbarch)
 /* Misc helper functions for targets. */
 
 int
-frame_num_args_unknown (struct frame_info *fi)
-{
-  return -1;
-}
-
-
-int
-generic_register_convertible_not (int num)
+deprecated_register_convertible_not (int num)
 {
   return 0;
 }
@@ -299,88 +272,22 @@ no_op_reg_to_regnum (int reg)
   return reg;
 }
 
-/* For use by frame_args_address and frame_locals_address.  */
 CORE_ADDR
-default_frame_address (struct frame_info *fi)
-{
-  return fi->frame;
-}
-
-/* Default prepare_to_procced().  */
-int
-default_prepare_to_proceed (int select_it)
-{
-  return 0;
-}
-
-/* Generic prepare_to_proceed().  This one should be suitable for most
-   targets that support threads. */
-int
-generic_prepare_to_proceed (int select_it)
-{
-  ptid_t wait_ptid;
-  struct target_waitstatus wait_status;
-
-  /* Get the last target status returned by target_wait().  */
-  get_last_target_status (&wait_ptid, &wait_status);
-
-  /* Make sure we were stopped either at a breakpoint, or because
-     of a Ctrl-C.  */
-  if (wait_status.kind != TARGET_WAITKIND_STOPPED
-      || (wait_status.value.sig != TARGET_SIGNAL_TRAP &&
-          wait_status.value.sig != TARGET_SIGNAL_INT))
-    {
-      return 0;
-    }
-
-  if (!ptid_equal (wait_ptid, minus_one_ptid)
-      && !ptid_equal (inferior_ptid, wait_ptid))
-    {
-      /* Switched over from WAIT_PID.  */
-      CORE_ADDR wait_pc = read_pc_pid (wait_ptid);
-
-      if (wait_pc != read_pc ())
-       {
-         if (select_it)
-           {
-             /* Switch back to WAIT_PID thread.  */
-             inferior_ptid = wait_ptid;
-
-             /* FIXME: This stuff came from switch_to_thread() in
-                thread.c (which should probably be a public function).  */
-             flush_cached_frames ();
-             registers_changed ();
-             stop_pc = wait_pc;
-             select_frame (get_current_frame ());
-           }
-          /* We return 1 to indicate that there is a breakpoint here,
-             so we need to step over it before continuing to avoid
-             hitting it straight away. */
-          if (breakpoint_here_p (wait_pc))
-            {
-             return 1;
-            }
-       }
-    }
-  return 0;
-  
-}
-
-void
 init_frame_pc_noop (int fromleaf, struct frame_info *prev)
 {
-  return;
+  /* Do nothing, implies return the same PC value.  */
+  return get_frame_pc (prev);
 }
 
-void
+CORE_ADDR
 init_frame_pc_default (int fromleaf, struct frame_info *prev)
 {
-  if (fromleaf)
-    prev->pc = SAVED_PC_AFTER_CALL (prev->next);
-  else if (prev->next != NULL)
-    prev->pc = FRAME_SAVED_PC (prev->next);
+  if (fromleaf && DEPRECATED_SAVED_PC_AFTER_CALL_P ())
+    return DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev));
+  else if (get_next_frame (prev) != NULL)
+    return DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev));
   else
-    prev->pc = read_pc ();
+    return read_pc ();
 }
 
 void
@@ -402,15 +309,27 @@ cannot_register_not (int regnum)
 }
 
 /* Legacy version of target_virtual_frame_pointer().  Assumes that
-   there is an FP_REGNUM and that it is the same, cooked or raw.  */
+   there is an DEPRECATED_FP_REGNUM and that it is the same, cooked or
+   raw.  */
 
 void
 legacy_virtual_frame_pointer (CORE_ADDR pc,
                              int *frame_regnum,
                              LONGEST *frame_offset)
 {
-  gdb_assert (FP_REGNUM >= 0);
-  *frame_regnum = FP_REGNUM;
+  /* FIXME: cagney/2002-09-13: This code is used when identifying the
+     frame pointer of the current PC.  It is assuming that a single
+     register and an offset can determine this.  I think it should
+     instead generate a byte code expression as that would work better
+     with things like Dwarf2's CFI.  */
+  if (DEPRECATED_FP_REGNUM >= 0 && DEPRECATED_FP_REGNUM < NUM_REGS)
+    *frame_regnum = DEPRECATED_FP_REGNUM;
+  else if (SP_REGNUM >= 0 && SP_REGNUM < NUM_REGS)
+    *frame_regnum = SP_REGNUM;
+  else
+    /* Should this be an internal error?  I guess so, it is reflecting
+       an architectural limitation in the current design.  */
+    internal_error (__FILE__, __LINE__, "No virtual frame pointer available");
   *frame_offset = 0;
 }
 
@@ -421,21 +340,15 @@ int
 generic_register_size (int regnum)
 {
   gdb_assert (regnum >= 0 && regnum < NUM_REGS + NUM_PSEUDO_REGS);
-  return TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (regnum));
+  if (gdbarch_register_type_p (current_gdbarch))
+    return TYPE_LENGTH (gdbarch_register_type (current_gdbarch, regnum));
+  else
+    /* FIXME: cagney/2003-03-01: Once all architectures implement
+       gdbarch_register_type(), this entire function can go away.  It
+       is made obsolete by register_size().  */
+    return TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (regnum)); /* OK */
 }
 
-#if !defined (IN_SIGTRAMP)
-#if defined (SIGTRAMP_START)
-#define IN_SIGTRAMP(pc, name) \
-       ((pc) >= SIGTRAMP_START(pc)   \
-        && (pc) < SIGTRAMP_END(pc) \
-        )
-#else
-#define IN_SIGTRAMP(pc, name) \
-       (name && STREQ ("_sigtramp", name))
-#endif
-#endif
-
 /* Assume all registers are adjacent.  */
 
 int
@@ -447,7 +360,7 @@ generic_register_byte (int regnum)
   byte = 0;
   for (i = 0; i < regnum; i++)
     {
-      byte += TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (i));
+      byte += generic_register_size (i);
     }
   return byte;
 }
@@ -456,27 +369,40 @@ generic_register_byte (int regnum)
 int
 legacy_pc_in_sigtramp (CORE_ADDR pc, char *name)
 {
-  return IN_SIGTRAMP(pc, name);
+#if !defined (IN_SIGTRAMP)
+  if (SIGTRAMP_START_P ())
+    return (pc) >= SIGTRAMP_START (pc) && (pc) < SIGTRAMP_END (pc);
+  else
+    return name && strcmp ("_sigtramp", name) == 0;
+#else
+  return IN_SIGTRAMP (pc, name);
+#endif
 }
 
 int
-legacy_convert_register_p (int regnum)
+legacy_convert_register_p (int regnum, struct type *type)
 {
-  return REGISTER_CONVERTIBLE (regnum);
+  return DEPRECATED_REGISTER_CONVERTIBLE (regnum);
 }
 
 void
-legacy_register_to_value (int regnum, struct type *type,
-                         char *from, char *to)
+legacy_register_to_value (struct frame_info *frame, int regnum,
+                         struct type *type, void *to)
 {
-  REGISTER_CONVERT_TO_VIRTUAL (regnum, type, from, to);
+  char from[MAX_REGISTER_SIZE];
+  frame_read_register (frame, regnum, from);
+  DEPRECATED_REGISTER_CONVERT_TO_VIRTUAL (regnum, type, from, to);
 }
 
 void
-legacy_value_to_register (struct type *type, int regnum,
-                         char *from, char *to)
+legacy_value_to_register (struct frame_info *frame, int regnum,
+                         struct type *type, const void *tmp)
 {
-  REGISTER_CONVERT_TO_RAW (type, regnum, from, to);
+  char to[MAX_REGISTER_SIZE];
+  char *from = alloca (TYPE_LENGTH (type));
+  memcpy (from, from, TYPE_LENGTH (type));
+  DEPRECATED_REGISTER_CONVERT_TO_RAW (type, regnum, from, to);
+  put_frame_register (frame, regnum, to);
 }
 
 \f
@@ -897,11 +823,12 @@ gdbarch_info_init (struct gdbarch_info *info)
 {
   memset (info, 0, sizeof (struct gdbarch_info));
   info->byte_order = BFD_ENDIAN_UNKNOWN;
+  info->osabi = GDB_OSABI_UNINITIALIZED;
 }
 
 /* */
 
-extern initialize_file_ftype _initialize_gdbarch_utils;
+extern initialize_file_ftype _initialize_gdbarch_utils; /* -Wmissing-prototypes */
 
 void
 _initialize_gdbarch_utils (void)
This page took 0.030656 seconds and 4 git commands to generate.