* i386.h: Correct opcode values for fsubp, fsubrp, fdivp, and
[deliverable/binutils-gdb.git] / gdb / utils.c
index 22e511c45f9e8bed558fc185a2aa044639c79cfe..abb7d11ded114e47fdc15838c37fe69c6bed19f7 100644 (file)
@@ -1,5 +1,5 @@
 /* General utility routines for GDB, the GNU debugger.
-   Copyright 1986, 1989, 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
+   Copyright 1986, 89, 90, 91, 92, 95, 1996 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -18,11 +18,6 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
-#if !defined(__GO32__) && !defined(__WIN32__) && !defined(MPW)
-#include <sys/ioctl.h>
-#include <sys/param.h>
-#include <pwd.h>
-#endif
 #ifdef ANSI_PROTOTYPES
 #include <stdarg.h>
 #else
@@ -51,13 +46,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /* Prototypes for local functions */
 
-#if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
-#else
+static void vfprintf_maybe_filtered PARAMS ((FILE *, const char *, va_list, int));
 
-static void
-malloc_botch PARAMS ((void));
+static void fputs_maybe_filtered PARAMS ((const char *, FILE *, int));
 
-#endif /* NO_MMALLOC, etc */
+#if !defined (NO_MMALLOC) && !defined (NO_MMCHECK)
+static void malloc_botch PARAMS ((void));
+#endif
 
 static void
 fatal_dump_core PARAMS((char *, ...));
@@ -225,7 +220,7 @@ free_current_contents (location)
 /* ARGSUSED */
 void
 null_cleanup (arg)
-    char **arg;
+    PTR arg;
 {
 }
 
@@ -399,8 +394,10 @@ fatal_dump_core (va_alist)
   fprintf_unfiltered (gdb_stderr, "\n");
   va_end (args);
 
+#ifndef _WIN32
   signal (SIGQUIT, SIG_DFL);
   kill (getpid (), SIGQUIT);
+#endif
   /* We should never get here, but just in case...  */
   exit (1);
 }
@@ -536,7 +533,7 @@ quit ()
 }
 
 
-#if defined(__GO32__)||defined(WINGDB)
+#if defined(__GO32__) || defined(_WIN32)
 
 /* In the absence of signals, poll keyboard for a quit.
    Called from #define QUIT pollquit() in xm-go32.h. */
@@ -546,6 +543,7 @@ pollquit()
 {
   if (kbhit ())
     {
+#ifndef _WIN32
       int k = getkey ();
       if (k == 1) {
        quit_flag = 1;
@@ -560,16 +558,20 @@ pollquit()
          /* We just ignore it */
          fprintf_unfiltered (gdb_stderr, "CTRL-A to quit, CTRL-B to quit harder\n");
        }
+#else
+      abort ();
+#endif
     }
 }
 
 
 #endif
-#if defined(__GO32__)||defined(WINGDB)
+#if defined(__GO32__) || defined(_WIN32)
 void notice_quit()
 {
   if (kbhit ())
     {
+#ifndef _WIN32
       int k = getkey ();
       if (k == 1) {
        quit_flag = 1;
@@ -582,6 +584,9 @@ void notice_quit()
        {
          fprintf_unfiltered (gdb_stderr, "CTRL-A to quit, CTRL-B to quit harder\n");
        }
+#else
+      abort ();
+#endif
     }
 }
 #else
@@ -619,19 +624,15 @@ request_quit (signo)
 \f
 /* Memory management stuff (malloc friends).  */
 
-#if defined (NO_MMALLOC)
-
 /* Make a substitute size_t for non-ANSI compilers. */
 
-#ifdef _AIX
-#include <stddef.h>
-#else /* Not AIX */
-#ifndef __STDC__
+#ifndef HAVE_STDDEF_H
 #ifndef size_t
 #define size_t unsigned int
 #endif
 #endif
-#endif /* Not AIX */
+
+#if defined (NO_MMALLOC)
 
 PTR
 mmalloc (md, size)
@@ -663,7 +664,7 @@ mfree (md, ptr)
 
 #endif /* NO_MMALLOC */
 
-#if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
+#if defined (NO_MMALLOC) || defined (NO_MMCHECK)
 
 void
 init_malloc (md)
@@ -671,7 +672,7 @@ init_malloc (md)
 {
 }
 
-#else /* have mmalloc and want corruption checking  */
+#else /* Have mmalloc and want corruption checking */
 
 static void
 malloc_botch ()
@@ -683,7 +684,7 @@ malloc_botch ()
    by MD, to detect memory corruption.  Note that MD may be NULL to specify
    the default heap that grows via sbrk.
 
-   Note that for freshly created regions, we must call mmcheck prior to any
+   Note that for freshly created regions, we must call mmcheckf prior to any
    mallocs in the region.  Otherwise, any region which was allocated prior to
    installing the checking hooks, which is later reallocated or freed, will
    fail the checks!  The mmcheck function only allows initial hooks to be
@@ -693,13 +694,24 @@ malloc_botch ()
 
    Returns zero on failure, non-zero on success. */
 
+#ifndef MMCHECK_FORCE
+#define MMCHECK_FORCE 0
+#endif
+
 void
 init_malloc (md)
      PTR md;
 {
-  if (!mmcheck (md, malloc_botch))
+  if (!mmcheckf (md, malloc_botch, MMCHECK_FORCE))
     {
-      warning ("internal error: failed to install memory consistency checks");
+      /* Don't use warning(), which relies on current_target being set
+        to something other than dummy_target, until after
+        initialize_all_files(). */
+
+      fprintf_unfiltered
+       (gdb_stderr, "warning: failed to install memory consistency checks; ");
+      fprintf_unfiltered
+       (gdb_stderr, "configuration should define NO_MMCHECK or MMCHECK_FORCE\n");
     }
 
   mmtrace ();
@@ -777,7 +789,7 @@ xmrealloc (md, ptr, size)
 
 PTR
 xmalloc (size)
-     long size;
+     size_t size;
 {
   return (xmmalloc ((PTR) NULL, size));
 }
@@ -787,7 +799,7 @@ xmalloc (size)
 PTR
 xrealloc (ptr, size)
      PTR ptr;
-     long size;
+     size_t size;
 {
   return (xmrealloc ((PTR) NULL, ptr, size));
 }
@@ -1492,7 +1504,7 @@ fputc_unfiltered (c, stream)
 static void
 vfprintf_maybe_filtered (stream, format, args, filter)
      FILE *stream;
-     char *format;
+     const char *format;
      va_list args;
      int filter;
 {
@@ -1865,14 +1877,14 @@ initialize_utils ()
   
   /* These defaults will be used if we are unable to get the correct
      values from termcap.  */
-#if defined(__GO32__) || defined(__WIN32__)
+#if defined(__GO32__)
   lines_per_page = ScreenRows();
   chars_per_line = ScreenCols();
 #else  
   lines_per_page = 24;
   chars_per_line = 80;
 
-#ifndef MPW
+#if !defined MPW && !defined _WIN32
   /* No termcap under MPW, although might be cool to do something
      by looking at worksheet or console window sizes. */
   /* Initialize the screen height and width from termcap.  */
@@ -1951,8 +1963,7 @@ initialize_utils ()
         SIGWINCH_HANDLER_BODY
 #endif
 \f
-#ifdef HAVE_LONG_DOUBLE
-/* Support for converting target fp numbers into host long double format.  */
+/* Support for converting target fp numbers into host DOUBLEST format.  */
 
 /* XXX - This code should really be in libiberty/floatformat.c, however
    configuration issues with libiberty made this very difficult to do in the
@@ -2019,22 +2030,23 @@ get_field (data, order, total_len, start, len)
   return result;
 }
   
-/* Convert from FMT to a long double.
+/* Convert from FMT to a DOUBLEST.
    FROM is the address of the extended float.
-   Store the long double in *TO.  */
+   Store the DOUBLEST in *TO.  */
 
 void
-floatformat_to_long_double (fmt, from, to)
+floatformat_to_doublest (fmt, from, to)
      const struct floatformat *fmt;
      char *from;
-     long double *to;
+     DOUBLEST *to;
 {
   unsigned char *ufrom = (unsigned char *)from;
-  long double dto;
+  DOUBLEST dto;
   long exponent;
   unsigned long mant;
   unsigned int mant_bits, mant_off;
   int mant_bits_left;
+  int special_exponent;                /* It's a NaN, denorm or zero */
 
   exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
                        fmt->exp_start, fmt->exp_len);
@@ -2045,7 +2057,12 @@ floatformat_to_long_double (fmt, from, to)
   mant_bits_left = fmt->man_len;
   mant_off = fmt->man_start;
   dto = 0.0;
-  exponent -= fmt->exp_bias;
+
+  special_exponent = exponent == 0 || exponent == fmt->exp_nan;
+
+/* Don't bias zero's, denorms or NaNs.  */
+  if (!special_exponent)
+    exponent -= fmt->exp_bias;
 
   /* Build the result algebraically.  Might go infinite, underflow, etc;
      who cares. */
@@ -2053,10 +2070,11 @@ floatformat_to_long_double (fmt, from, to)
 /* If this format uses a hidden bit, explicitly add it in now.  Otherwise,
    increment the exponent by one to account for the integer bit.  */
 
-  if (fmt->intbit == floatformat_intbit_no)
-    dto = ldexp (1.0, exponent);
-  else
-    exponent++;
+  if (!special_exponent)
+    if (fmt->intbit == floatformat_intbit_no)
+      dto = ldexp (1.0, exponent);
+    else
+      exponent++;
 
   while (mant_bits_left > 0)
     {
@@ -2074,7 +2092,7 @@ floatformat_to_long_double (fmt, from, to)
   /* Negate it if negative.  */
   if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
     dto = -dto;
-  memcpy (to, &dto, sizeof (dto));
+  *to = dto;
 }
 \f
 static void put_field PARAMS ((unsigned char *, enum floatformat_byteorders,
@@ -2134,6 +2152,7 @@ put_field (data, order, total_len, start, len, stuff_to_put)
     }
 }
 
+#ifdef HAVE_LONG_DOUBLE
 /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
    The range of the returned value is >= 0.5 and < 1.0.  This is equivalent to
    frexp, but operates on the long double data type.  */
@@ -2178,20 +2197,22 @@ ldfrexp (value, eptr)
   *eptr = exp;
   return value/tmp;
 }
+#endif /* HAVE_LONG_DOUBLE */
+
 
-/* The converse: convert the long double *FROM to an extended float
+/* The converse: convert the DOUBLEST *FROM to an extended float
    and store where TO points.  Neither FROM nor TO have any alignment
    restrictions.  */
 
 void
-floatformat_from_long_double (fmt, from, to)
+floatformat_from_doublest (fmt, from, to)
      CONST struct floatformat *fmt;
-     long double *from;
+     DOUBLEST *from;
      char *to;
 {
-  long double dfrom;
+  DOUBLEST dfrom;
   int exponent;
-  long double mant;
+  DOUBLEST mant;
   unsigned int mant_bits, mant_off;
   int mant_bits_left;
   unsigned char *uto = (unsigned char *)to;
@@ -2220,7 +2241,12 @@ floatformat_from_long_double (fmt, from, to)
 
   /* How to tell an infinity from an ordinary number?  FIXME-someday */
 
+#ifdef HAVE_LONG_DOUBLE
   mant = ldfrexp (dfrom, &exponent);
+#else
+  mant = frexp (dfrom, &exponent);
+#endif
+
   put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, fmt->exp_len,
             exponent + fmt->exp_bias - 1);
 
@@ -2242,10 +2268,11 @@ floatformat_from_long_double (fmt, from, to)
       if (mant_bits_left == fmt->man_len
          && fmt->intbit == floatformat_intbit_no)
        {
-         mant_long &= 0x7fffffff;
+         mant_long <<= 1;
          mant_bits -= 1;
        }
-      else if (mant_bits < 32)
+
+      if (mant_bits < 32)
        {
          /* The bits we want are in the most significant MANT_BITS bits of
             mant_long.  Move them to the least significant.  */
@@ -2259,4 +2286,62 @@ floatformat_from_long_double (fmt, from, to)
     }
 }
 
-#endif /* HAVE_LONG_DOUBLE */
+/* temporary storage using circular buffer */
+#define MAXCELLS 16
+#define CELLSIZE 32
+char* 
+get_cell()
+{
+  static char buf[MAXCELLS][CELLSIZE];
+  static int cell=0;
+  if (++cell>MAXCELLS) cell=0;
+  return buf[cell];
+}
+
+/* print routines to handle variable size regs, etc */
+char* 
+paddr(addr)
+  t_addr addr;
+{
+  char *paddr_str=get_cell();
+  switch (sizeof(t_addr))
+    {
+      case 8:
+        sprintf(paddr_str,"%08x%08x",
+               (unsigned long)(addr>>32),(unsigned long)(addr&0xffffffff));
+       break;
+      case 4:
+        sprintf(paddr_str,"%08x",(unsigned long)addr);
+       break;
+      case 2:
+        sprintf(paddr_str,"%04x",(unsigned short)(addr&0xffff));
+       break;
+      default:
+        sprintf(paddr_str,"%x",addr);
+    }
+  return paddr_str;
+}
+
+char* 
+preg(reg)
+  t_reg reg;
+{
+  char *preg_str=get_cell();
+  switch (sizeof(t_reg))
+    {
+      case 8:
+        sprintf(preg_str,"%08x%08x",
+               (unsigned long)(reg>>32),(unsigned long)(reg&0xffffffff));
+       break;
+      case 4:
+        sprintf(preg_str,"%08x",(unsigned long)reg);
+       break;
+      case 2:
+        sprintf(preg_str,"%04x",(unsigned short)(reg&0xffff));
+       break;
+      default:
+        sprintf(preg_str,"%x",reg);
+    }
+  return preg_str;
+}
+
This page took 0.028179 seconds and 4 git commands to generate.