* gdbtypes.c (create_string_type): Receive character type as argument.
authorUlrich Weigand <uweigand@de.ibm.com>
Wed, 17 Jun 2009 18:47:35 +0000 (18:47 +0000)
committerUlrich Weigand <uweigand@de.ibm.com>
Wed, 17 Jun 2009 18:47:35 +0000 (18:47 +0000)
* gdbtypes.h (create_string_type): Add character type argument.
        * dwarf2read.c (read_tag_string_type): Pass character type to
create_string_type.

* value.h (value_string): Add character type argument.
* valops.c (value_string): Add character type argument.  Pass it to
create_string_type.  Do not allocate space in inferior.
* valarith.c (value_concat): Pass character type to value_string.

* value.h (value_typed_string): Rename to ...
(value_cstring): ... this.
* valops.c (value_typed_string): Rename to ...
(value_cstring): ... this.
* c-lang.c (evaluate_subexp_c): Update.

* python/python-value.c (builtin_type_pychar): New define.
(convert_value_from_python): Call value_cstring instead
of value_from_string.
* value.c (value_from_string): Remove.
* value.h (value_from_string): Remove.

* eval.c (evaluate_subexp_standard): Pass character type to
value_string.  Pass expression architecture to value_nsstring
and lookup_child_selector.
* objc-lang.h (lookup_objc_class): Add GDBARCH parameter.
(lookup_child_selector): Likewise.
(value_nsstring): Likewise.
* objc-lang.c (lookup_objc_class): Add GDBARCH parameter.
Pass character type to value_string..
(lookup_child_selector): Likewise.
(value_nsstring): Add GDBARCH parameter, use it instead of
objfile architecture.  Pass architecture to lookup_objc_class
and lookup_child_selector. Pass character type to value_string.
(end_msglist): Pass architecture to lookup_objc_class.
* objc-exp.y: Pass architecture to lookup_objc_class.

14 files changed:
gdb/ChangeLog
gdb/c-lang.c
gdb/dwarf2read.c
gdb/eval.c
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/objc-exp.y
gdb/objc-lang.c
gdb/objc-lang.h
gdb/python/python-value.c
gdb/valarith.c
gdb/valops.c
gdb/value.c
gdb/value.h

index 2c277d72015148ddf487b10de8c59dfc32b99547..ec1e3d5ee7758fc94269f76acbc7fe9f4f378903 100644 (file)
@@ -1,3 +1,42 @@
+2009-06-17  Ulrich Weigand  <uweigand@de.ibm.com>
+
+       * gdbtypes.c (create_string_type): Receive character type as argument.
+       * gdbtypes.h (create_string_type): Add character type argument.
+       * dwarf2read.c (read_tag_string_type): Pass character type to
+       create_string_type.
+
+       * value.h (value_string): Add character type argument.
+       * valops.c (value_string): Add character type argument.  Pass it to
+       create_string_type.  Do not allocate space in inferior.
+       * valarith.c (value_concat): Pass character type to value_string.
+
+       * value.h (value_typed_string): Rename to ...
+       (value_cstring): ... this.
+       * valops.c (value_typed_string): Rename to ...
+       (value_cstring): ... this.
+       * c-lang.c (evaluate_subexp_c): Update.
+
+       * python/python-value.c (builtin_type_pychar): New define.
+       (convert_value_from_python): Call value_cstring instead
+       of value_from_string.
+       * value.c (value_from_string): Remove.
+       * value.h (value_from_string): Remove.
+
+       * eval.c (evaluate_subexp_standard): Pass character type to
+       value_string.  Pass expression architecture to value_nsstring
+       and lookup_child_selector.
+       * objc-lang.h (lookup_objc_class): Add GDBARCH parameter.
+       (lookup_child_selector): Likewise.
+       (value_nsstring): Likewise.
+       * objc-lang.c (lookup_objc_class): Add GDBARCH parameter.
+       Pass character type to value_string..
+       (lookup_child_selector): Likewise.
+       (value_nsstring): Add GDBARCH parameter, use it instead of
+       objfile architecture.  Pass architecture to lookup_objc_class
+       and lookup_child_selector. Pass character type to value_string.
+       (end_msglist): Pass architecture to lookup_objc_class.
+       * objc-exp.y: Pass architecture to lookup_objc_class.
+
 2009-06-17  Ulrich Weigand  <uweigand@de.ibm.com>
 
        * gdbtypes.h (struct language_defn): Add forward declaration.
index 109d4a169b9d746bd53ff971f817ec7a78009095..898ae8ddb8b4e91b8c9c7afba3d1bf0ba877723d 100644 (file)
@@ -951,7 +951,7 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
            if ((dest_type & C_CHAR) != 0)
              result = allocate_value (type);
            else
-             result = value_typed_string ("", 0, type);
+             result = value_cstring ("", 0, type);
            do_cleanups (cleanup);
            return result;
          }
@@ -971,9 +971,9 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
            /* Write the terminating character.  */
            for (i = 0; i < TYPE_LENGTH (type); ++i)
              obstack_1grow (&output, 0);
-           result = value_typed_string (obstack_base (&output),
-                                        obstack_object_size (&output),
-                                        type);
+           result = value_cstring (obstack_base (&output),
+                                   obstack_object_size (&output),
+                                   type);
          }
        do_cleanups (cleanup);
        return result;
index 26baba56a779946a0d69a80597e45db43f2922c5..ae8870c262fc253a682a12a21a0deda99ca93343 100644 (file)
@@ -5165,6 +5165,7 @@ static struct type *
 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *type, *range_type, *index_type, *char_type;
   struct attribute *attr;
   unsigned int length;
@@ -5190,7 +5191,8 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
 
   index_type = builtin_type_int32;
   range_type = create_range_type (NULL, index_type, 1, length);
-  type = create_string_type (NULL, range_type);
+  char_type = language_string_char_type (cu->language_defn, gdbarch);
+  type = create_string_type (NULL, char_type, range_type);
 
   return set_die_type (die, type, cu);
 }
index e64d4bf52f9da9e8efad1100f8cb880666a1e8ab..df730057d80edc8b63f7b15366375dc35c83d5ae 100644 (file)
@@ -789,7 +789,8 @@ evaluate_subexp_standard (struct type *expect_type,
       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
       if (noside == EVAL_SKIP)
        goto nosideret;
-      return value_string (&exp->elts[pc + 2].string, tem);
+      type = language_string_char_type (exp->language_defn, exp->gdbarch);
+      return value_string (&exp->elts[pc + 2].string, tem, type);
 
     case OP_OBJC_NSSTRING:             /* Objective C Foundation Class NSString constant.  */
       tem = longest_to_int (exp->elts[pc + 1].longconst);
@@ -798,7 +799,7 @@ evaluate_subexp_standard (struct type *expect_type,
        {
          goto nosideret;
        }
-      return (struct value *) value_nsstring (&exp->elts[pc + 2].string, tem + 1);
+      return value_nsstring (exp->gdbarch, &exp->elts[pc + 2].string, tem + 1);
 
     case OP_BITSTRING:
       tem = longest_to_int (exp->elts[pc + 1].longconst);
@@ -1010,7 +1011,8 @@ evaluate_subexp_standard (struct type *expect_type,
          sel[len] = 0;         /* Make sure it's terminated.  */
 
        selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
-       return value_from_longest (selector_type, lookup_child_selector (sel));
+       return value_from_longest (selector_type,
+                                  lookup_child_selector (exp->gdbarch, sel));
       }
 
     case OP_OBJC_MSGCALL:
@@ -1098,16 +1100,20 @@ evaluate_subexp_standard (struct type *expect_type,
           the verification method than the non-standard, but more
           often used, 'NSObject' class. Make sure we check for both. */
 
-       responds_selector = lookup_child_selector ("respondsToSelector:");
+       responds_selector
+         = lookup_child_selector (exp->gdbarch, "respondsToSelector:");
        if (responds_selector == 0)
-         responds_selector = lookup_child_selector ("respondsTo:");
+         responds_selector
+           = lookup_child_selector (exp->gdbarch, "respondsTo:");
        
        if (responds_selector == 0)
          error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
        
-       method_selector = lookup_child_selector ("methodForSelector:");
+       method_selector
+         = lookup_child_selector (exp->gdbarch, "methodForSelector:");
        if (method_selector == 0)
-         method_selector = lookup_child_selector ("methodFor:");
+         method_selector
+           = lookup_child_selector (exp->gdbarch, "methodFor:");
        
        if (method_selector == 0)
          error (_("no 'methodFor:' or 'methodForSelector:' method"));
index 17df58e13f2e30b8734cb4eb5a9d9f7bd3c0fd40..005a29d1dad332c2bcd3c7c6ed71fea580354f8a 100644 (file)
@@ -846,13 +846,10 @@ create_array_type (struct type *result_type,
    type?  */
 
 struct type *
-create_string_type (struct type *result_type, 
+create_string_type (struct type *result_type,
+                   struct type *string_char_type,
                    struct type *range_type)
 {
-  struct type *string_char_type;
-      
-  string_char_type = language_string_char_type (current_language,
-                                               current_gdbarch);
   result_type = create_array_type (result_type,
                                   string_char_type,
                                   range_type);
index f23aedeef1f69a1cb5cd23c535216b7a22014b54..c5175efb5f9bcbe2e4397e6ea5713040109b14dd 100644 (file)
@@ -1177,7 +1177,8 @@ extern struct type *create_range_type (struct type *, struct type *, int,
 extern struct type *create_array_type (struct type *, struct type *,
                                       struct type *);
 
-extern struct type *create_string_type (struct type *, struct type *);
+extern struct type *create_string_type (struct type *, struct type *,
+                                       struct type *);
 
 extern struct type *create_set_type (struct type *, struct type *);
 
index 1a31f5edc825995306e4420a050899116148a8da..8103de6e073f7b6ba80b91c42bba1a90783314b9 100644 (file)
@@ -333,7 +333,8 @@ exp :       '[' TYPENAME
                        {
                          CORE_ADDR class;
 
-                         class = lookup_objc_class (copy_name ($2.stoken));
+                         class = lookup_objc_class (parse_gdbarch,
+                                                    copy_name ($2.stoken));
                          if (class == 0)
                            error ("%s is not an ObjC Class", 
                                   copy_name ($2.stoken));
@@ -1748,7 +1749,7 @@ yylex ()
     /* See if it's an ObjC classname.  */
     if (!sym)
       {
-       CORE_ADDR Class = lookup_objc_class(tmp);
+       CORE_ADDR Class = lookup_objc_class (parse_gdbarch, tmp);
        if (Class)
          {
            yylval.class.class = Class;
index cd4c1977c4e977aaefaeef803a3097d99982fdde..cff54bbaffd0e179842b16a062abf53e867a004e 100644 (file)
@@ -108,8 +108,9 @@ lookup_struct_typedef (char *name, struct block *block, int noerr)
 }
 
 CORE_ADDR 
-lookup_objc_class (char *classname)
+lookup_objc_class (struct gdbarch *gdbarch, char *classname)
 {
+  struct type *char_type = builtin_type (gdbarch)->builtin_char;
   struct value * function, *classval;
 
   if (! target_has_execution)
@@ -128,15 +129,16 @@ lookup_objc_class (char *classname)
       return 0;
     }
 
-  classval = value_string (classname, strlen (classname) + 1);
+  classval = value_string (classname, strlen (classname) + 1, char_type);
   classval = value_coerce_array (classval);
   return (CORE_ADDR) value_as_long (call_function_by_hand (function, 
                                                           1, &classval));
 }
 
 CORE_ADDR
-lookup_child_selector (char *selname)
+lookup_child_selector (struct gdbarch *gdbarch, char *selname)
 {
+  struct type *char_type = builtin_type (gdbarch)->builtin_char;
   struct value * function, *selstring;
 
   if (! target_has_execution)
@@ -156,53 +158,50 @@ lookup_child_selector (char *selname)
     }
 
   selstring = value_coerce_array (value_string (selname, 
-                                               strlen (selname) + 1));
+                                               strlen (selname) + 1, char_type));
   return value_as_long (call_function_by_hand (function, 1, &selstring));
 }
 
 struct value * 
-value_nsstring (char *ptr, int len)
+value_nsstring (struct gdbarch *gdbarch, char *ptr, int len)
 {
+  struct type *char_type = builtin_type (gdbarch)->builtin_char;
   struct value *stringValue[3];
   struct value *function, *nsstringValue;
   struct symbol *sym;
   struct type *type;
-  struct objfile *objf;
-  struct gdbarch *gdbarch;
 
   if (!target_has_execution)
     return 0;          /* Can't call into inferior to create NSString.  */
 
-  stringValue[2] = value_string(ptr, len);
+  stringValue[2] = value_string(ptr, len, char_type);
   stringValue[2] = value_coerce_array(stringValue[2]);
   /* _NSNewStringFromCString replaces "istr" after Lantern2A.  */
   if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0))
     {
-      function = find_function_in_inferior("_NSNewStringFromCString", &objf);
+      function = find_function_in_inferior("_NSNewStringFromCString", NULL);
       nsstringValue = call_function_by_hand(function, 1, &stringValue[2]);
     }
   else if (lookup_minimal_symbol("istr", 0, 0))
     {
-      function = find_function_in_inferior("istr", &objf);
+      function = find_function_in_inferior("istr", NULL);
       nsstringValue = call_function_by_hand(function, 1, &stringValue[2]);
     }
   else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0))
     {
       function
-       = find_function_in_inferior("+[NSString stringWithCString:]", &objf);
-      type = builtin_type (get_objfile_arch (objf))->builtin_long;
+       = find_function_in_inferior("+[NSString stringWithCString:]", NULL);
+      type = builtin_type (gdbarch)->builtin_long;
 
       stringValue[0] = value_from_longest 
-       (type, lookup_objc_class ("NSString"));
+       (type, lookup_objc_class (gdbarch, "NSString"));
       stringValue[1] = value_from_longest 
-       (type, lookup_child_selector ("stringWithCString:"));
+       (type, lookup_child_selector (gdbarch, "stringWithCString:"));
       nsstringValue = call_function_by_hand(function, 3, &stringValue[0]);
     }
   else
     error (_("NSString: internal error -- no way to create new NSString"));
 
-  gdbarch = get_objfile_arch (objf);
-
   sym = lookup_struct_typedef("NSString", 0, 1);
   if (sym == NULL)
     sym = lookup_struct_typedef("NXString", 0, 1);
@@ -612,7 +611,7 @@ end_msglist(void)
   selname_chain = sel->next;
   msglist_len = sel->msglist_len;
   msglist_sel = sel->msglist_sel;
-  selid = lookup_child_selector(p);
+  selid = lookup_child_selector (parse_gdbarch, p);
   if (!selid)
     error (_("Can't find selector \"%s\""), p);
   write_exp_elt_longcst (selid);
index d0cbb8dc55a9bc6539cea74bf5fe36fbe0274631..0d23467c67bc1c20f9fb6aafb9b34f8f0e184560 100644 (file)
@@ -29,8 +29,10 @@ extern int objc_parse (void);                /* Defined in c-exp.y */
 
 extern void objc_error (char *);       /* Defined in c-exp.y */
 
-extern CORE_ADDR lookup_objc_class     (char *classname);
-extern CORE_ADDR lookup_child_selector (char *methodname);
+extern CORE_ADDR lookup_objc_class     (struct gdbarch *gdbarch,
+                                       char *classname);
+extern CORE_ADDR lookup_child_selector (struct gdbarch *gdbarch,
+                                       char *methodname);
 
 extern char *objc_demangle (const char *mangled, int options);
 
@@ -46,7 +48,8 @@ extern char *find_imps (struct symtab *symtab, struct block *block,
                        char *method, struct symbol **syms, 
                        unsigned int *nsym, unsigned int *ndebug);
 
-extern struct value *value_nsstring (char *ptr, int len);
+extern struct value *value_nsstring (struct gdbarch *gdbarch,
+                                    char *ptr, int len);
 
 /* for parsing Objective C */
 extern void start_msglist (void);
index 46af318e61008225b15b898a71c206661fb2a3ab..1b34f47c2716a5c5d6fb112ddd95d251a4cfeba1 100644 (file)
@@ -55,6 +55,9 @@ struct value *values_in_python = NULL;
 #define builtin_type_pybool \
   language_bool_type (current_language, current_gdbarch)
 
+#define builtin_type_pychar \
+  language_string_char_type (current_language, current_gdbarch)
+
 typedef struct {
   PyObject_HEAD
   struct value *value;
@@ -867,7 +870,7 @@ convert_value_from_python (PyObject *obj)
          if (s != NULL)
            {
              old = make_cleanup (xfree, s);
-             value = value_from_string (s);
+             value = value_cstring (s, strlen (s), builtin_type_pychar);
              do_cleanups (old);
            }
        }
index 57e6194c7f9503d1a33106efa9a05ad087f5f417..6f08705b7577eb8ba388299b67a5186212a3094e 100644 (file)
@@ -624,6 +624,7 @@ value_concat (struct value *arg1, struct value *arg2)
   char inchar;
   struct type *type1 = check_typedef (value_type (arg1));
   struct type *type2 = check_typedef (value_type (arg2));
+  struct type *char_type;
 
   /* First figure out if we are dealing with two values to be concatenated
      or a repeat count and a value to be repeated.  INVAL1 is set to the
@@ -659,6 +660,7 @@ value_concat (struct value *arg1, struct value *arg2)
          ptr = (char *) alloca (count * inval2len);
          if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
            {
+             char_type = type2;
              inchar = (char) unpack_long (type2,
                                           value_contents (inval2));
              for (idx = 0; idx < count; idx++)
@@ -668,13 +670,14 @@ value_concat (struct value *arg1, struct value *arg2)
            }
          else
            {
+             char_type = TYPE_TARGET_TYPE (type2);
              for (idx = 0; idx < count; idx++)
                {
                  memcpy (ptr + (idx * inval2len), value_contents (inval2),
                          inval2len);
                }
            }
-         outval = value_string (ptr, count * inval2len);
+         outval = value_string (ptr, count * inval2len, char_type);
        }
       else if (TYPE_CODE (type2) == TYPE_CODE_BITSTRING
               || TYPE_CODE (type2) == TYPE_CODE_BOOL)
@@ -700,10 +703,12 @@ value_concat (struct value *arg1, struct value *arg2)
       ptr = (char *) alloca (inval1len + inval2len);
       if (TYPE_CODE (type1) == TYPE_CODE_CHAR)
        {
+         char_type = type1;
          *ptr = (char) unpack_long (type1, value_contents (inval1));
        }
       else
        {
+         char_type = TYPE_TARGET_TYPE (type1);
          memcpy (ptr, value_contents (inval1), inval1len);
        }
       if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
@@ -715,7 +720,7 @@ value_concat (struct value *arg1, struct value *arg2)
        {
          memcpy (ptr + inval1len, value_contents (inval2), inval2len);
        }
-      outval = value_string (ptr, inval1len + inval2len);
+      outval = value_string (ptr, inval1len + inval2len, char_type);
     }
   else if (TYPE_CODE (type1) == TYPE_CODE_BITSTRING
           || TYPE_CODE (type1) == TYPE_CODE_BOOL)
index 422821ab1e63f72a9433ff44634f130738c10782..05585c997af25c5048d045181a3699064beca34f 100644 (file)
@@ -1349,7 +1349,7 @@ value_array (int lowbound, int highbound, struct value **elemvec)
 }
 
 struct value *
-value_typed_string (char *ptr, int len, struct type *char_type)
+value_cstring (char *ptr, int len, struct type *char_type)
 {
   struct value *val;
   int lowbound = current_language->string_lower_bound;
@@ -1376,34 +1376,21 @@ value_typed_string (char *ptr, int len, struct type *char_type)
    string may contain embedded null bytes.  */
 
 struct value *
-value_string (char *ptr, int len)
+value_string (char *ptr, int len, struct type *char_type)
 {
   struct value *val;
   int lowbound = current_language->string_lower_bound;
+  int highbound = len / TYPE_LENGTH (char_type);
   struct type *rangetype = create_range_type ((struct type *) NULL,
                                              builtin_type_int32,
                                              lowbound, 
-                                             len + lowbound - 1);
+                                             highbound + lowbound - 1);
   struct type *stringtype
-    = create_string_type ((struct type *) NULL, rangetype);
-  CORE_ADDR addr;
-
-  if (current_language->c_style_arrays == 0)
-    {
-      val = allocate_value (stringtype);
-      memcpy (value_contents_raw (val), ptr, len);
-      return val;
-    }
+    = create_string_type ((struct type *) NULL, char_type, rangetype);
 
-
-  /* Allocate space to store the string in the inferior, and then copy
-     LEN bytes from PTR in gdb to that address in the inferior.  */
-
-  addr = allocate_space_in_inferior (len);
-  write_memory (addr, (gdb_byte *) ptr, len);
-
-  val = value_at_lazy (stringtype, addr);
-  return (val);
+  val = allocate_value (stringtype);
+  memcpy (value_contents_raw (val), ptr, len);
+  return val;
 }
 
 struct value *
index aec3b4b500e7272cc8b50f184632e8c54056d49b..7566921c80f6785295c0ca81a49c2bcb654d02e1 100644 (file)
@@ -2025,34 +2025,6 @@ value_from_pointer (struct type *type, CORE_ADDR addr)
 }
 
 
-/* Create a value for a string constant to be stored locally
-   (not in the inferior's memory space, but in GDB memory).
-   This is analogous to value_from_longest, which also does not
-   use inferior memory.  String shall NOT contain embedded nulls.  */
-
-struct value *
-value_from_string (char *ptr)
-{
-  struct value *val;
-  int len = strlen (ptr);
-  int lowbound = current_language->string_lower_bound;
-  struct type *string_char_type;
-  struct type *rangetype;
-  struct type *stringtype;
-
-  rangetype = create_range_type ((struct type *) NULL,
-                                builtin_type_int32,
-                                lowbound, len + lowbound - 1);
-  string_char_type = language_string_char_type (current_language,
-                                               current_gdbarch);
-  stringtype = create_array_type ((struct type *) NULL,
-                                 string_char_type,
-                                 rangetype);
-  val = allocate_value (stringtype);
-  memcpy (value_contents_raw (val), ptr, len);
-  return val;
-}
-
 /* Create a value of type TYPE whose contents come from VALADDR, if it
    is non-null, and whose memory address (in the inferior) is
    ADDRESS.  */
index 317d4ef8ce6bb21f1b13b190abb6f26c2b7f21f4..db4dcc1dd43c42e9577b864d33da813837e648b0 100644 (file)
@@ -339,7 +339,6 @@ extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
 extern struct value *value_from_double (struct type *type, DOUBLEST num);
 extern struct value *value_from_decfloat (struct type *type,
                                          const gdb_byte *decbytes);
-extern struct value *value_from_string (char *string);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
@@ -381,9 +380,10 @@ extern struct value *value_mark (void);
 
 extern void value_free_to_mark (struct value *mark);
 
-extern struct value *value_typed_string (char *ptr, int len,
-                                        struct type *char_type);
-extern struct value *value_string (char *ptr, int len);
+extern struct value *value_cstring (char *ptr, int len,
+                                   struct type *char_type);
+extern struct value *value_string (char *ptr, int len,
+                                  struct type *char_type);
 extern struct value *value_bitstring (char *ptr, int len);
 
 extern struct value *value_array (int lowbound, int highbound,
This page took 0.062096 seconds and 4 git commands to generate.