* Bringing over SKY PKE disassembler feature from sky branch.
[deliverable/binutils-gdb.git] / gdb / valprint.c
index 591978a4f10147859693c49e3ae17e39c4fb02e3..c5d01b188de5e99e6ddbca030e4020e05be325e0 100644 (file)
@@ -16,7 +16,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "gdb_string.h"
@@ -30,6 +30,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "language.h"
 #include "demangle.h"
 #include "annotate.h"
+#include "valprint.h"
 
 #include <errno.h>
 
@@ -135,6 +136,7 @@ val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
      int recurse;
      enum val_prettyprint pretty;
 {
+  struct type *real_type = check_typedef (type);
   if (pretty == Val_pretty_default)
     {
       pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint;
@@ -146,8 +148,7 @@ val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
      only a stub and we can't find and substitute its complete type, then
      print appropriate string and return.  */
 
-  check_stub_type (type);
-  if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
+  if (TYPE_FLAGS (real_type) & TYPE_FLAG_STUB)
     {
       fprintf_filtered (stream, "<incomplete type>");
       gdb_flush (stream);
@@ -183,7 +184,9 @@ value_print (val, stream, format, pretty)
   return LA_VALUE_PRINT (val, stream, format, pretty);
 }
 
-/*  Called by various <lang>_val_print routines to print TYPE_CODE_INT's */
+/* Called by various <lang>_val_print routines to print
+   TYPE_CODE_INT's.  TYPE is the type.  VALADDR is the address of the
+   value.  STREAM is where to print the value.  */
 
 void
 val_print_type_code_int (type, valaddr, stream)
@@ -191,74 +194,22 @@ val_print_type_code_int (type, valaddr, stream)
      char *valaddr;
      GDB_FILE *stream;
 {
-  char *p;
-  /* Pointer to first (i.e. lowest address) nonzero character.  */
-  char *first_addr;
-  unsigned int len;
-
   if (TYPE_LENGTH (type) > sizeof (LONGEST))
     {
-      if (TYPE_UNSIGNED (type))
-       {
-         /* First figure out whether the number in fact has zeros
-            in all its bytes more significant than least significant
-            sizeof (LONGEST) ones.  */
-         len = TYPE_LENGTH (type);
-         
-         if (TARGET_BYTE_ORDER == BIG_ENDIAN)
-           {
-             for (p = valaddr;
-                  len > sizeof (LONGEST) && p < valaddr + TYPE_LENGTH (type);
-                  p++)
-               {
-                 if (*p == 0)
-                   {
-                     len--;
-                   }
-                 else
-                   {
-                     break;
-                   }
-               }
-             first_addr = p;
-           }
-         else
-           {
-             first_addr = valaddr;
-             for (p = valaddr + TYPE_LENGTH (type) - 1;
-                  len > sizeof (LONGEST) && p >= valaddr;
-                  p--)
-               {
-                 if (*p == 0)
-                   {
-                     len--;
-                   }
-                 else
-                   {
-                     break;
-                   }
-               }
-           }
+      LONGEST val;
 
-         if (len <= sizeof (LONGEST))
-           {
-             /* The most significant bytes are zero, so we can just get
-                the least significant sizeof (LONGEST) bytes and print it
-                in decimal.  */
-             print_longest (stream, 'u', 0,
-                            extract_unsigned_integer (first_addr,
-                                                      sizeof (LONGEST)));
-           }
-         else
-           {
-             /* It is big, so print it in hex.  */
-             print_hex_chars (stream, (unsigned char *) first_addr, len);
-           }
+      if (TYPE_UNSIGNED (type)
+         && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type),
+                                           &val))
+       {
+         print_longest (stream, 'u', 0, val);
        }
       else
        {
-         /* Signed.  One could assume two's complement (a reasonable
-            assumption, I think) and do better than this.  */
+         /* Signed, or we couldn't turn an unsigned value into a
+            LONGEST.  For signed values, one could assume two's
+            complement (a reasonable assumption, I think) and do
+            better than this.  */
          print_hex_chars (stream, (unsigned char *) valaddr,
                           TYPE_LENGTH (type));
        }
@@ -294,15 +245,60 @@ print_longest (stream, format, use_local, val_long)
 {
 #if defined (CC_HAS_LONG_LONG) && !defined (PRINTF_HAS_LONG_LONG)
   long vtop, vbot;
-
-  vtop = val_long >> (sizeof (long) * HOST_CHAR_BIT);
+  unsigned int ui_max = UINT_MAX;
+  unsigned long long val_ulonglong;
+
+  /* Do shift in two operations so that if sizeof (long) == sizeof (LONGEST)
+     we can avoid warnings from picky compilers about shifts >= the size of
+     the shiftee in bits */
+  vtop = val_long >> (sizeof (long) * HOST_CHAR_BIT - 1);
+  vtop >>= 1;
   vbot = (long) val_long;
-
-  if ((format == 'd' && (val_long < INT_MIN || val_long > INT_MAX))
-      || ((format == 'u' || format == 'x') && (unsigned long long)val_long > UINT_MAX))
+  val_ulonglong = (unsigned long long) val_long;
+  switch (format)
     {
-      fprintf_filtered (stream, "0x%lx%08lx", vtop, vbot);
-      return;
+    case 'd':
+      if (val_long < INT_MIN || val_long > INT_MAX)
+       {
+         if (sizeof (long long) > sizeof (long))
+           {
+             fprintf_filtered (stream, "0x%lx%08lx", vtop, vbot);
+           }
+         else
+           {
+             fprintf_filtered (stream, "%d", vbot);
+           }
+         return;
+       }
+      break;
+    case 'x':
+      if (val_ulonglong > ui_max)
+       {
+         if (sizeof (long long) > sizeof (long))
+           {
+             fprintf_filtered (stream, "0x%lx%08lx", vtop, vbot);
+           }
+         else
+           {
+             fprintf_filtered (stream, "0x%lx", vbot);
+           }
+         return;
+       }
+      break;
+    case 'u':
+      if (val_ulonglong > ui_max)
+       {
+         if (sizeof (long long) > sizeof (long))
+           {
+             fprintf_filtered (stream, "0x%lx%08lx", vtop, vbot);
+           }
+         else
+           {
+             fprintf_filtered (stream, "%lu", (unsigned long) vbot);
+           }
+         return;
+       }
+      break;
     }
 #endif
 
@@ -411,8 +407,10 @@ longest_to_int (arg)
   if (sizeof (LONGEST) <= sizeof (int))
     return arg;
 
-  if (arg > INT_MAX || arg < INT_MIN)
-    error ("Value out of range.");
+  if (arg > INT_MAX)
+    error ("Value is larger than largest signed integer.");
+  if (arg < INT_MIN)
+    error ("Value is smaller than smallest signed integer.");
 
   return arg;
 }
@@ -426,7 +424,7 @@ print_floating (valaddr, type, stream)
      struct type *type;
      GDB_FILE *stream;
 {
-  double doub;
+  DOUBLEST doub;
   int inv;
   unsigned len = TYPE_LENGTH (type);
   
@@ -504,9 +502,22 @@ print_floating (valaddr, type, stream)
 
   doub = unpack_double (type, valaddr, &inv);
   if (inv)
-    fprintf_filtered (stream, "<invalid float value>");
+    {
+      fprintf_filtered (stream, "<invalid float value>");
+      return;
+    }
+
+  if (len < sizeof (double))
+    fprintf_filtered (stream, "%.9g", (double) doub);
+  else if (len == sizeof (double))
+    fprintf_filtered (stream, "%.17g", (double) doub);
   else
-    fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub);
+#ifdef PRINTF_HAS_LONG_DOUBLE
+    fprintf_filtered (stream, "%.35Lg", doub);
+#else
+    /* This at least wins with values that are representable as doubles */
+    fprintf_filtered (stream, "%.17g", (double) doub);
+#endif
 }
 
 /* VALADDR points to an integer of LEN bytes.  Print it in hex on stream.  */
@@ -576,7 +587,7 @@ val_print_array_elements (type, valaddr, address, stream, format, deref_ref,
   unsigned int reps;
       
   elttype = TYPE_TARGET_TYPE (type);
-  eltlen = TYPE_LENGTH (elttype);
+  eltlen = TYPE_LENGTH (check_typedef (elttype));
   len = TYPE_LENGTH (type) / eltlen;
 
   annotate_array_section_begin (i, elttype);
@@ -632,63 +643,6 @@ val_print_array_elements (type, valaddr, address, stream, format, deref_ref,
     }
 }
 
-void
-value_print_array_elements (val, stream, format, pretty)
-     value_ptr val;
-     GDB_FILE *stream;
-     int format;
-     enum val_prettyprint pretty;
-{
-  unsigned int things_printed = 0;
-  register unsigned int i, n, typelen;
-  /* Position of the array elem we are examining to see if it is repeated.  */
-  unsigned int rep1;
-  /* Number of repetitions we have detected so far.  */
-  unsigned int reps;
-    
-  n = VALUE_REPETITIONS (val);
-  typelen = TYPE_LENGTH (VALUE_TYPE (val));
-  for (i = 0; i < n && things_printed < print_max; i++)
-    {
-      if (i != 0)
-       {
-         fprintf_filtered (stream, ", ");
-       }
-      wrap_here ("");
-      
-      rep1 = i + 1;
-      reps = 1;
-      while (rep1 < n && !memcmp (VALUE_CONTENTS (val) + typelen * i,
-                                 VALUE_CONTENTS (val) + typelen * rep1,
-                                 typelen))
-       {
-         ++reps;
-         ++rep1;
-       }
-      
-      if (reps > repeat_count_threshold)
-       {
-         val_print (VALUE_TYPE (val), VALUE_CONTENTS (val) + typelen * i,
-                    VALUE_ADDRESS (val) + typelen * i, stream, format, 1,
-                    0, pretty);
-         fprintf_filtered (stream, " <repeats %u times>", reps);
-         i = rep1 - 1;
-         things_printed += repeat_count_threshold;
-       }
-      else
-       {
-         val_print (VALUE_TYPE (val), VALUE_CONTENTS (val) + typelen * i,
-                    VALUE_ADDRESS (val) + typelen * i, stream, format, 1,
-                    0, pretty);
-         things_printed++;
-       }
-    }
-  if (i < n)
-    {
-      fprintf_filtered (stream, "...");
-    }
-}
-
 /*  Print a string from the inferior, starting at ADDR and printing up to LEN
     characters, to STREAM.  If LEN is zero, printing stops at the first null
     byte, otherwise printing proceeds (including null bytes) until either
@@ -712,7 +666,7 @@ val_print_string (addr, len, stream)
   unsigned int fetchlimit;     /* Maximum number of bytes to fetch. */
   unsigned int nfetch;         /* Bytes to fetch / bytes fetched. */
   unsigned int chunksize;      /* Size of each fetch, in bytes. */
-  int bufsize;                 /* Size of current fetch buffer. */
+  unsigned int bufsize;                /* Size of current fetch buffer. */
   char *buffer = NULL;         /* Dynamically growable fetch buffer. */
   char *bufptr;                        /* Pointer to next available byte in buffer. */
   char *limit;                 /* First location past end of fetch buffer. */
This page took 0.027834 seconds and 4 git commands to generate.