Fix the documentation of valprint.c:value_print.
[deliverable/binutils-gdb.git] / gdb / valprint.c
index 4011e5e9695d0aa547f6d7bc9dd406bc416382f5..9468b2209453d0ee1236bd2cb2ac9c2db805b695 100644 (file)
@@ -2,7 +2,7 @@
 
    Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
    1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-   2009 Free Software Foundation, Inc.
+   2009, 2010 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -366,10 +366,11 @@ common_val_print (struct value *val, struct ui_file *stream, int recurse,
                    stream, recurse, options, language);
 }
 
-/* Print the value VAL in C-ish syntax on stream STREAM according to
-   OPTIONS.
-   If the object printed is a string pointer, returns
-   the number of string bytes printed.  */
+/* Print on stream STREAM the value VAL according to OPTIONS.  The value
+   is printed using the current_language syntax.
+
+   If the object printed is a string pointer, return the number of string
+   bytes printed.  */
 
 int
 value_print (struct value *val, struct ui_file *stream,
@@ -409,7 +410,7 @@ val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
 
       if (TYPE_UNSIGNED (type)
          && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type),
-                                           &val))
+                                           byte_order, &val))
        {
          print_longest (stream, 'u', 0, val);
        }
@@ -605,10 +606,11 @@ void
 print_decimal_floating (const gdb_byte *valaddr, struct type *type,
                        struct ui_file *stream)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
   char decstr[MAX_DECIMAL_STRING];
   unsigned len = TYPE_LENGTH (type);
 
-  decimal_to_string (valaddr, len, decstr);
+  decimal_to_string (valaddr, len, byte_order, decstr);
   fputs_filtered (decstr, stream);
   return;
 }
@@ -1268,7 +1270,7 @@ partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int *errnoptr
 
 int
 read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
-            gdb_byte **buffer, int *bytes_read)
+            enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read)
 {
   int found_nul;               /* Non-zero if we found the nul char.  */
   int errcode;                 /* Errno returned from bad reads.  */
@@ -1340,7 +1342,7 @@ read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
            {
              unsigned long c;
 
-             c = extract_unsigned_integer (bufptr, width);
+             c = extract_unsigned_integer (bufptr, width, byte_order);
              addr += width;
              bufptr += width;
              if (c == 0)
@@ -1393,6 +1395,8 @@ val_print_string (struct type *elttype, CORE_ADDR addr, int len,
   int bytes_read;
   gdb_byte *buffer = NULL;     /* Dynamically growable fetch buffer.  */
   struct cleanup *old_chain = NULL;    /* Top of the old cleanup chain.  */
+  struct gdbarch *gdbarch = get_type_arch (elttype);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int width = TYPE_LENGTH (elttype);
 
   /* First we need to figure out the limit on the number of characters we are
@@ -1405,7 +1409,8 @@ val_print_string (struct type *elttype, CORE_ADDR addr, int len,
 
   fetchlimit = (len == -1 ? options->print_max : min (len, options->print_max));
 
-  errcode = read_string (addr, len, width, fetchlimit, &buffer, &bytes_read);
+  errcode = read_string (addr, len, width, fetchlimit, byte_order,
+                        &buffer, &bytes_read);
   old_chain = make_cleanup (xfree, buffer);
 
   addr += bytes_read;
@@ -1414,8 +1419,8 @@ val_print_string (struct type *elttype, CORE_ADDR addr, int len,
      terminated early due to an error or finding a null char when LEN is -1.  */
 
   /* Determine found_nul by looking at the last character read.  */
-  found_nul = extract_unsigned_integer (buffer + bytes_read - width, width) == 0;
-
+  found_nul = extract_unsigned_integer (buffer + bytes_read - width, width,
+                                       byte_order) == 0;
   if (len == -1 && !found_nul)
     {
       gdb_byte *peekbuf;
@@ -1427,7 +1432,7 @@ val_print_string (struct type *elttype, CORE_ADDR addr, int len,
       peekbuf = (gdb_byte *) alloca (width);
 
       if (target_read_memory (addr, peekbuf, width) == 0
-         && extract_unsigned_integer (peekbuf, width) != 0)
+         && extract_unsigned_integer (peekbuf, width, byte_order) != 0)
        force_ellipsis = 1;
     }
   else if ((len >= 0 && errcode != 0) || (len > bytes_read / width))
@@ -1455,13 +1460,13 @@ val_print_string (struct type *elttype, CORE_ADDR addr, int len,
       if (errcode == EIO)
        {
          fprintf_filtered (stream, " <Address ");
-         fputs_filtered (paddress (addr), stream);
+         fputs_filtered (paddress (gdbarch, addr), stream);
          fprintf_filtered (stream, " out of bounds>");
        }
       else
        {
          fprintf_filtered (stream, " <Error reading address ");
-         fputs_filtered (paddress (addr), stream);
+         fputs_filtered (paddress (gdbarch, addr), stream);
          fprintf_filtered (stream, ": %s>", safe_strerror (errcode));
        }
     }
This page took 0.044473 seconds and 4 git commands to generate.