2010-12-23 Yao Qi <yao@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / c-lang.c
index 305c549caaaf924dc4c4659a5e8c637e1b50374a..775a6f83e8458e8daeb1ccc3910a9540933814f7 100644 (file)
@@ -35,6 +35,7 @@
 #include "cp-support.h"
 #include "gdb_obstack.h"
 #include <ctype.h>
+#include "exceptions.h"
 
 extern void _initialize_c_language (void);
 
@@ -179,6 +180,7 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len,
             int quoter, int *need_escapep)
 {
   int need_escape = *need_escapep;
+
   *need_escapep = 0;
   if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
                                            && w != LCST ('8')
@@ -223,6 +225,7 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len,
              {
                char octal[30];
                ULONGEST value;
+
                value = extract_unsigned_integer (&orig[i], width, byte_order);
                /* If the value fits in 3 octal digits, print it that
                   way.  Otherwise, print it as a hex escape.  */
@@ -236,6 +239,7 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len,
            while (i < orig_len)
              {
                char octal[5];
+
                sprintf (octal, "\\%.3o", orig[i] & 0xff);
                append_string_as_wide (octal, output);
                ++i;
@@ -387,6 +391,19 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
   int finished = 0;
   int need_escape = 0;
 
+  if (length == -1)
+    {
+      unsigned long current_char = 1;
+
+      for (i = 0; current_char; ++i)
+       {
+         QUIT;
+         current_char = extract_unsigned_integer (string + i * width,
+                                                  width, byte_order);
+       }
+      length = i;
+    }
+
   /* If the string was not truncated due to `set print elements', and
      the last byte of it is a null, we don't print that, in traditional C
      style.  */
@@ -421,18 +438,6 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
       return;
     }
 
-  if (length == -1)
-    {
-      unsigned long current_char = 1;
-      for (i = 0; current_char; ++i)
-       {
-         QUIT;
-         current_char = extract_unsigned_integer (string + i * width,
-                                                  width, byte_order);
-       }
-      length = i;
-    }
-
   /* Arrange to iterate over the characters, in wchar_t form.  */
   iter = make_wchar_iterator (string, length * width, encoding, width);
   cleanup = make_cleanup_wchar_iterator (iter);
@@ -504,6 +509,7 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
                /* Painful gyrations.  */
                int j;
                char *s = xstrprintf (_(" <repeats %u times>"), reps);
+
                for (j = 0; s[j]; ++j)
                  {
                    gdb_wchar_t w = gdb_btowc (s[j]);
@@ -693,13 +699,19 @@ c_get_string (struct value *value, gdb_byte **buffer, int *length,
     }
   else
     {
-      err = read_string (value_as_address (value), *length, width, fetchlimit,
-                        byte_order, buffer, length);
+      CORE_ADDR addr = value_as_address (value);
+
+      err = read_string (addr, *length, width, fetchlimit,
+                        byte_order, buffer, length);
       if (err)
        {
          xfree (*buffer);
-         error (_("Error reading string from inferior: %s"),
-                safe_strerror (err));
+         if (err == EIO)
+           throw_error (MEMORY_ERROR, "Address %s out of bounds",
+                        paddress (get_type_arch (type), addr));
+         else
+           error (_("Error reading string from inferior: %s"),
+                  safe_strerror (err));
        }
     }
 
@@ -881,6 +893,7 @@ convert_escape (struct type *type, const char *dest_charset,
     case 'U':
       {
        int length = *p == 'u' ? 4 : 8;
+
        ADVANCE;
        if (!isxdigit (*p))
          error (_("\\u used with no following hex digits"));
@@ -908,6 +921,7 @@ parse_one_string (struct obstack *output, char *data, int len,
   while (data < limit)
     {
       char *p = data;
+
       /* Look for next escape, or the end of the input.  */
       while (p < limit && *p != '\\')
        ++p;
@@ -926,7 +940,7 @@ parse_one_string (struct obstack *output, char *data, int len,
    are delegated to evaluate_subexp_standard; see that function for a
    description of the arguments.  */
 
-static struct value *
+struct value *
 evaluate_subexp_c (struct type *expect_type, struct expression *exp,
                   int *pos, enum noside noside)
 {
@@ -1021,6 +1035,7 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
        else
          {
            int i;
+
            /* Write the terminating character.  */
            for (i = 0; i < TYPE_LENGTH (type); ++i)
              obstack_1grow (&output, 0);
@@ -1107,6 +1122,7 @@ c_language_arch_info (struct gdbarch *gdbarch,
                      struct language_arch_info *lai)
 {
   const struct builtin_type *builtin = builtin_type (gdbarch);
+
   lai->string_char_type = builtin->builtin_char;
   lai->primitive_type_vector
     = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
@@ -1213,6 +1229,7 @@ cplus_language_arch_info (struct gdbarch *gdbarch,
                          struct language_arch_info *lai)
 {
   const struct builtin_type *builtin = builtin_type (gdbarch);
+
   lai->string_char_type = builtin->builtin_char;
   lai->primitive_type_vector
     = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
This page took 0.025648 seconds and 4 git commands to generate.