Add GPL copyright notices to uncopyrighted files.
[deliverable/binutils-gdb.git] / gdb / valprint.c
index 2f07114ff962697f2ad4d37fe887c56d0b5a08b9..7e6308cde8ee31efa6ed2d8642d9abb93e51b0e6 100644 (file)
@@ -1,5 +1,5 @@
 /* Print values for GDB, the GNU debugger.
-   Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1998
+   Copyright 1986, 1988, 1989, 1991-1994, 1998, 2000
    Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 /* Prototypes for local functions */
 
-static void print_hex_chars PARAMS ((GDB_FILE *, unsigned char *,
-                                    unsigned int));
+static int partial_memory_read (CORE_ADDR memaddr, char *myaddr,
+                               int len, int *errnoptr);
 
-static void show_print PARAMS ((char *, int));
+static void print_hex_chars (struct ui_file *, unsigned char *,
+                            unsigned int);
 
-static void set_print PARAMS ((char *, int));
+static void show_print (char *, int);
 
-static void set_radix PARAMS ((char *, int));
+static void set_print (char *, int);
 
-static void show_radix PARAMS ((char *, int));
+static void set_radix (char *, int);
 
-static void set_input_radix PARAMS ((char *, int, struct cmd_list_element *));
+static void show_radix (char *, int);
 
-static void set_input_radix_1 PARAMS ((int, unsigned));
+static void set_input_radix (char *, int, struct cmd_list_element *);
 
-static void set_output_radix PARAMS ((char *, int, struct cmd_list_element *));
+static void set_input_radix_1 (int, unsigned);
 
-static void set_output_radix_1 PARAMS ((int, unsigned));
+static void set_output_radix (char *, int, struct cmd_list_element *);
 
-void _initialize_valprint PARAMS ((void));
+static void set_output_radix_1 (int, unsigned);
+
+void _initialize_valprint (void);
 
 /* Maximum number of chars to print for a string pointer value or vector
    contents, or UINT_MAX for no limit.  Note that "set print elements 0"
@@ -127,7 +130,7 @@ val_print (type, valaddr, embedded_offset, address,
      char *valaddr;
      int embedded_offset;
      CORE_ADDR address;
-     GDB_FILE *stream;
+     struct ui_file *stream;
      int format;
      int deref_ref;
      int recurse;
@@ -164,7 +167,7 @@ val_print (type, valaddr, embedded_offset, address,
 int
 value_print (val, stream, format, pretty)
      value_ptr val;
-     GDB_FILE *stream;
+     struct ui_file *stream;
      int format;
      enum val_prettyprint pretty;
 {
@@ -189,7 +192,7 @@ void
 val_print_type_code_int (type, valaddr, stream)
      struct type *type;
      char *valaddr;
-     GDB_FILE *stream;
+     struct ui_file *stream;
 {
   if (TYPE_LENGTH (type) > sizeof (LONGEST))
     {
@@ -237,10 +240,11 @@ val_print_type_code_int (type, valaddr, stream)
  */
 
 #if defined (CC_HAS_LONG_LONG) && !defined (PRINTF_HAS_LONG_LONG)
-static void print_decimal PARAMS ((GDB_FILE * stream, char *sign, int use_local, ULONGEST val_ulong));
+static void print_decimal (struct ui_file * stream, char *sign,
+                          int use_local, ULONGEST val_ulong);
 static void
 print_decimal (stream, sign, use_local, val_ulong)
-     GDB_FILE *stream;
+     struct ui_file *stream;
      char *sign;
      int use_local;
      ULONGEST val_ulong;
@@ -277,7 +281,7 @@ print_decimal (stream, sign, use_local, val_ulong)
 
 void
 print_longest (stream, format, use_local, val_long)
-     GDB_FILE *stream;
+     struct ui_file *stream;
      int format;
      int use_local;
      LONGEST val_long;
@@ -557,6 +561,7 @@ longest_to_int (arg)
   return (rtnval);
 }
 
+
 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
    on STREAM.  */
 
@@ -564,85 +569,88 @@ void
 print_floating (valaddr, type, stream)
      char *valaddr;
      struct type *type;
-     GDB_FILE *stream;
+     struct ui_file *stream;
 {
   DOUBLEST doub;
   int inv;
   unsigned len = TYPE_LENGTH (type);
 
-#if defined (IEEE_FLOAT)
-
   /* Check for NaN's.  Note that this code does not depend on us being
      on an IEEE conforming system.  It only depends on the target
      machine using IEEE representation.  This means (a)
      cross-debugging works right, and (2) IEEE_FLOAT can (and should)
-     be defined for systems like the 68881, which uses IEEE
+     be non-zero for systems like the 68881, which uses IEEE
      representation, but is not IEEE conforming.  */
+  if (IEEE_FLOAT)
+    {
+      unsigned long low, high;
+      /* Is the sign bit 0?  */
+      int nonnegative;
+      /* Is it is a NaN (i.e. the exponent is all ones and
+        the fraction is nonzero)?  */
+      int is_nan;
+
+      /* For lint, initialize these two variables to suppress warning: */
+      low = high = nonnegative = 0;
+      if (len == 4)
+       {
+         /* It's single precision.  */
+         /* Assume that floating point byte order is the same as
+            integer byte order.  */
+         low = extract_unsigned_integer (valaddr, 4);
+         nonnegative = ((low & 0x80000000) == 0);
+         is_nan = ((((low >> 23) & 0xFF) == 0xFF)
+                   && 0 != (low & 0x7FFFFF));
+         low &= 0x7fffff;
+         high = 0;
+       }
+      else if (len == 8)
+       {
+         /* It's double precision.  Get the high and low words.  */
 
-  {
-    unsigned long low, high;
-    /* Is the sign bit 0?  */
-    int nonnegative;
-    /* Is it is a NaN (i.e. the exponent is all ones and
-       the fraction is nonzero)?  */
-    int is_nan;
-
-    /* For lint, initialize these two variables to suppress warning: */
-    low = high = nonnegative = 0;
-    if (len == 4)
-      {
-       /* It's single precision.  */
-       /* Assume that floating point byte order is the same as
-          integer byte order.  */
-       low = extract_unsigned_integer (valaddr, 4);
-       nonnegative = ((low & 0x80000000) == 0);
-       is_nan = ((((low >> 23) & 0xFF) == 0xFF)
-                 && 0 != (low & 0x7FFFFF));
-       low &= 0x7fffff;
-       high = 0;
-      }
-    else if (len == 8)
-      {
-       /* It's double precision.  Get the high and low words.  */
-
-       /* Assume that floating point byte order is the same as
-          integer byte order.  */
-       if (TARGET_BYTE_ORDER == BIG_ENDIAN)
-         {
-           low = extract_unsigned_integer (valaddr + 4, 4);
-           high = extract_unsigned_integer (valaddr, 4);
-         }
-       else
-         {
-           low = extract_unsigned_integer (valaddr, 4);
-           high = extract_unsigned_integer (valaddr + 4, 4);
-         }
-       nonnegative = ((high & 0x80000000) == 0);
-       is_nan = (((high >> 20) & 0x7ff) == 0x7ff
-                 && !((((high & 0xfffff) == 0)) && (low == 0)));
-       high &= 0xfffff;
-      }
-    else
-      /* Extended.  We can't detect NaNs for extendeds yet.  Also note
-         that currently extendeds get nuked to double in
-         REGISTER_CONVERTIBLE.  */
-      is_nan = 0;
-
-    if (is_nan)
-      {
-       /* The meaning of the sign and fraction is not defined by IEEE.
-          But the user might know what they mean.  For example, they
-          (in an implementation-defined manner) distinguish between
-          signaling and quiet NaN's.  */
-       if (high)
-         fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative,
-                           high, low);
-       else
-         fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
-       return;
-      }
-  }
-#endif /* IEEE_FLOAT.  */
+         /* Assume that floating point byte order is the same as
+            integer byte order.  */
+         if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+           {
+             low = extract_unsigned_integer (valaddr + 4, 4);
+             high = extract_unsigned_integer (valaddr, 4);
+           }
+         else
+           {
+             low = extract_unsigned_integer (valaddr, 4);
+             high = extract_unsigned_integer (valaddr + 4, 4);
+           }
+         nonnegative = ((high & 0x80000000) == 0);
+         is_nan = (((high >> 20) & 0x7ff) == 0x7ff
+                   && !((((high & 0xfffff) == 0)) && (low == 0)));
+         high &= 0xfffff;
+       }
+      else
+       {
+#ifdef TARGET_ANALYZE_FLOATING
+         TARGET_ANALYZE_FLOATING;
+#else
+         /* Extended.  We can't detect extended NaNs for this target.
+            Also note that currently extendeds get nuked to double in
+            REGISTER_CONVERTIBLE.  */
+         is_nan = 0;
+#endif 
+       }
+
+      if (is_nan)
+       {
+         /* The meaning of the sign and fraction is not defined by IEEE.
+            But the user might know what they mean.  For example, they
+            (in an implementation-defined manner) distinguish between
+            signaling and quiet NaN's.  */
+         if (high)
+           fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + !!nonnegative,
+                             high, low);
+         else
+           fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
+         return;
+       }
+    }
 
   doub = unpack_double (type, valaddr, &inv);
   if (inv)
@@ -666,7 +674,7 @@ print_floating (valaddr, type, stream)
 
 void
 print_binary_chars (stream, valaddr, len)
-     GDB_FILE *stream;
+     struct ui_file *stream;
      unsigned char *valaddr;
      unsigned len;
 {
@@ -674,7 +682,7 @@ print_binary_chars (stream, valaddr, len)
 #define BITS_IN_BYTES 8
 
   unsigned char *p;
-  int i;
+  unsigned int i;
   int b;
 
   /* Declared "int" so it will be signed.
@@ -730,7 +738,7 @@ print_binary_chars (stream, valaddr, len)
  */
 void
 print_octal_chars (stream, valaddr, len)
-     GDB_FILE *stream;
+     struct ui_file *stream;
      unsigned char *valaddr;
      unsigned len;
 {
@@ -881,7 +889,7 @@ print_octal_chars (stream, valaddr, len)
  */
 void
 print_decimal_chars (stream, valaddr, len)
-     GDB_FILE *stream;
+     struct ui_file *stream;
      unsigned char *valaddr;
      unsigned len;
 {
@@ -1024,7 +1032,7 @@ print_decimal_chars (stream, valaddr, len)
 
 static void
 print_hex_chars (stream, valaddr, len)
-     GDB_FILE *stream;
+     struct ui_file *stream;
      unsigned char *valaddr;
      unsigned len;
 {
@@ -1069,7 +1077,7 @@ val_print_array_elements (type, valaddr, address, stream, format, deref_ref,
      struct type *type;
      char *valaddr;
      CORE_ADDR address;
-     GDB_FILE *stream;
+     struct ui_file *stream;
      int format;
      int deref_ref;
      int recurse;
@@ -1143,6 +1151,47 @@ val_print_array_elements (type, valaddr, address, stream, format, deref_ref,
     }
 }
 
+/* Read LEN bytes of target memory at address MEMADDR, placing the
+   results in GDB's memory at MYADDR.  Returns a count of the bytes
+   actually read, and optionally an errno value in the location
+   pointed to by ERRNOPTR if ERRNOPTR is non-null. */
+
+/* FIXME: cagney/1999-10-14: Only used by val_print_string.  Can this
+   function be eliminated.  */
+
+static int
+partial_memory_read (CORE_ADDR memaddr, char *myaddr, int len, int *errnoptr)
+{
+  int nread;                   /* Number of bytes actually read. */
+  int errcode;                 /* Error from last read. */
+
+  /* First try a complete read. */
+  errcode = target_read_memory (memaddr, myaddr, len);
+  if (errcode == 0)
+    {
+      /* Got it all. */
+      nread = len;
+    }
+  else
+    {
+      /* Loop, reading one byte at a time until we get as much as we can. */
+      for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
+       {
+         errcode = target_read_memory (memaddr++, myaddr++, 1);
+       }
+      /* If an error, the last read was unsuccessful, so adjust count. */
+      if (errcode != 0)
+       {
+         nread--;
+       }
+    }
+  if (errnoptr != NULL)
+    {
+      *errnoptr = errcode;
+    }
+  return (nread);
+}
+
 /*  Print a string from the inferior, starting at ADDR and printing up to LEN
    characters, of WIDTH bytes a piece, to STREAM.  If LEN is -1, printing
    stops at the first null byte, otherwise printing proceeds (including null
@@ -1156,7 +1205,7 @@ val_print_string (addr, len, width, stream)
      CORE_ADDR addr;
      int len;
      int width;
-     GDB_FILE *stream;
+     struct ui_file *stream;
 {
   int force_ellipsis = 0;      /* Force ellipsis to be printed if nonzero. */
   int errcode;                 /* Errno returned from bad reads. */
@@ -1202,7 +1251,7 @@ val_print_string (addr, len, width, stream)
       bufptr = buffer;
       old_chain = make_cleanup (free, buffer);
 
-      nfetch = target_read_memory_partial (addr, bufptr, len * width, &errcode)
+      nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
        / width;
       addr += nfetch * width;
       bufptr += nfetch * width;
@@ -1228,7 +1277,7 @@ val_print_string (addr, len, width, stream)
          bufsize += nfetch;
 
          /* Read as much as we can. */
-         nfetch = target_read_memory_partial (addr, bufptr, nfetch * width, &errcode)
+         nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode)
            / width;
 
          /* Scan this chunk for the null byte that terminates the string
This page took 0.031044 seconds and 4 git commands to generate.