aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorUlrich Weigand <uweigand@de.ibm.com>2009-06-17 18:47:35 +0000
committerUlrich Weigand <uweigand@de.ibm.com>2009-06-17 18:47:35 +0000
commit3b7538c0317072d430eca4e808b183dac5bd5e45 (patch)
tree5d181808a477c585f4840272098ebd6c8b9f8321 /gdb
parente6c014f28ffa7d52bf7e9b599422f5ca910a17dd (diff)
downloadgdb-3b7538c0317072d430eca4e808b183dac5bd5e45.zip
gdb-3b7538c0317072d430eca4e808b183dac5bd5e45.tar.gz
gdb-3b7538c0317072d430eca4e808b183dac5bd5e45.tar.bz2
* 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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog39
-rw-r--r--gdb/c-lang.c8
-rw-r--r--gdb/dwarf2read.c4
-rw-r--r--gdb/eval.c20
-rw-r--r--gdb/gdbtypes.c7
-rw-r--r--gdb/gdbtypes.h3
-rw-r--r--gdb/objc-exp.y5
-rw-r--r--gdb/objc-lang.c33
-rw-r--r--gdb/objc-lang.h9
-rw-r--r--gdb/python/python-value.c5
-rw-r--r--gdb/valarith.c9
-rw-r--r--gdb/valops.c29
-rw-r--r--gdb/value.c28
-rw-r--r--gdb/value.h8
14 files changed, 111 insertions, 96 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2c277d7..ec1e3d5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,44 @@
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.
(lookup_typename): Add LANGUAGE and GDBARCH parameters.
(lookup_unsigned_typename): Likewise.
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 109d4a1..898ae8d 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -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;
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 26baba5..ae8870c 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -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);
}
diff --git a/gdb/eval.c b/gdb/eval.c
index e64d4bf..df730057 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -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"));
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 17df58e..005a29d 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -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);
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index f23aede..c5175ef 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -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 *);
diff --git a/gdb/objc-exp.y b/gdb/objc-exp.y
index 1a31f5e..8103de6 100644
--- a/gdb/objc-exp.y
+++ b/gdb/objc-exp.y
@@ -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;
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index cd4c197..cff54bb 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -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);
diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h
index d0cbb8d..0d23467 100644
--- a/gdb/objc-lang.h
+++ b/gdb/objc-lang.h
@@ -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);
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 46af318..1b34f47 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -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);
}
}
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 57e6194..6f08705 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -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)
diff --git a/gdb/valops.c b/gdb/valops.c
index 422821a..05585c9 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -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 *
diff --git a/gdb/value.c b/gdb/value.c
index aec3b4b..7566921 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -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. */
diff --git a/gdb/value.h b/gdb/value.h
index 317d4ef..db4dcc1 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -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,