gdb/doc/
[binutils-gdb.git] / gdb / p-lang.c
index 1722c0f4e03a04781c85403e3f6a05bb2595c9ee..64d2e9f9be6ab66b742b7ae692ba8e9b20f971bc 100644 (file)
@@ -1,6 +1,6 @@
 /* Pascal language support routines for GDB, the GNU debugger.
 
-   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -101,7 +101,7 @@ is_pascal_string_type (struct type *type,int *length_pos,
                       struct type **char_type,
                       char **arrayname)
 {
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+  if (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT)
     {
       /* Old Borland type pascal strings from Free Pascal Compiler.  */
       /* Two fields: length and st.  */
@@ -137,6 +137,7 @@ is_pascal_string_type (struct type *type,int *length_pos,
           if (char_type)
            {
              *char_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 2));
+
              if (TYPE_CODE (*char_type) == TYPE_CODE_ARRAY)
                *char_type = TYPE_TARGET_TYPE (*char_type);
            }
@@ -157,10 +158,7 @@ static void pascal_one_char (int, struct ui_file *, int *);
 static void
 pascal_one_char (int c, struct ui_file *stream, int *in_quotes)
 {
-
-  c &= 0xFF;                   /* Avoid sign bit follies */
-
-  if ((c == '\'') || (PRINT_LITERAL_FORM (c)))
+  if (c == '\'' || ((unsigned int) c <= 0xff && (PRINT_LITERAL_FORM (c))))
     {
       if (!(*in_quotes))
        fputs_filtered ("'", stream);
@@ -192,6 +190,7 @@ static void
 pascal_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
 {
   int in_quotes = 0;
+
   pascal_one_char (c, stream, &in_quotes);
   if (in_quotes)
     fputs_filtered ("'", stream);
@@ -201,6 +200,7 @@ void
 pascal_printchar (int c, struct type *type, struct ui_file *stream)
 {
   int in_quotes = 0;
+
   pascal_one_char (c, stream, &in_quotes);
   if (in_quotes)
     fputs_filtered ("'", stream);
@@ -214,7 +214,7 @@ pascal_printchar (int c, struct type *type, struct ui_file *stream)
 void
 pascal_printstr (struct ui_file *stream, struct type *type,
                 const gdb_byte *string, unsigned int length,
-                int force_ellipses,
+                const char *encoding, int force_ellipses,
                 const struct value_print_options *options)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
@@ -222,7 +222,11 @@ pascal_printstr (struct ui_file *stream, struct type *type,
   unsigned int things_printed = 0;
   int in_quotes = 0;
   int need_comma = 0;
-  int width = TYPE_LENGTH (type);
+  int width;
+
+  /* Preserve TYPE's original type, just set its LENGTH.  */
+  check_typedef (type);
+  width = TYPE_LENGTH (type);
 
   /* 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
@@ -372,6 +376,7 @@ pascal_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_pascal_primitive_types + 1,