This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFA: move value_from_contents_and_address to value.c
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 20 Nov 2008 18:10:07 -0700
- Subject: RFA: move value_from_contents_and_address to value.c
- Reply-to: tromey at redhat dot com
This is a mostly mechanical patch.
I had written a version of "value_from_contents" for use by the Python
pretty-printing code before I noticed that it already existed in
ada-lang.c.
This patch moves the function from ada-lang.c to value.c. It also
adds an "embedded_offset" argument. I think the move should be done
on maintenance grounds -- it is a reasonably generic function, and so
should not be in an Ada-specific file.
The new argument will be needed for pretty-printing support.
Conceptually I think you can see how it would be needed if a function
in the val_print hierarchy were to try to reconstruct a 'value'.
Built and regtested on x86-64 (compile farm).
Ok?
Tom
2008-11-20 Tom Tromey <tromey@redhat.com>
* ada-valprint.c (ada_val_print_1): Update.
(ada_value_print): Likewise.
* ada-tasks.c (read_atcb): Update.
* value.c (value_from_contents_and_address): Add 'embedded_offset'
argument. Move from ...
* ada-lang.c (value_from_contents_and_address): ...here.
(value_tag_from_contents_and_address): Update.
(ada_which_variant_applies): Likewise.
(ada_template_to_fixed_record_type_1): Likewise.
(to_record_with_fixed_variant_part): Likewise.
(ada_to_fixed_value_create): Likewise.
* ada-lang.h (value_from_contents_and_address): Don't declare.
* value.h (value_from_contents_and_address): Declare.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 2ccba78..1c1b640 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -465,26 +465,6 @@ is_suffix (const char *str, const char *suffix)
return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0);
}
-/* 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. */
-
-struct value *
-value_from_contents_and_address (struct type *type,
- const gdb_byte *valaddr,
- CORE_ADDR address)
-{
- struct value *v = allocate_value (type);
- if (valaddr == NULL)
- set_value_lazy (v, 1);
- else
- memcpy (value_contents_raw (v), valaddr, TYPE_LENGTH (type));
- VALUE_ADDRESS (v) = address;
- if (address != 0)
- VALUE_LVAL (v) = lval_memory;
- return v;
-}
-
/* The contents of value VAL, treated as a value of type TYPE. The
result is an lval in memory if VAL is. */
@@ -5614,7 +5594,7 @@ value_tag_from_contents_and_address (struct type *type,
: valaddr + tag_byte_offset);
CORE_ADDR address1 = (address == 0) ? 0 : address + tag_byte_offset;
- return value_from_contents_and_address (tag_type, valaddr1, address1);
+ return value_from_contents_and_address (tag_type, valaddr1, 0, address1);
}
return NULL;
}
@@ -6468,7 +6448,7 @@ ada_which_variant_applies (struct type *var_type, struct type *outer_type,
struct value *discrim;
LONGEST discrim_val;
- outer = value_from_contents_and_address (outer_type, outer_valaddr, 0);
+ outer = value_from_contents_and_address (outer_type, outer_valaddr, 0, 0);
discrim = ada_value_struct_elt (outer, discrim_name, 1);
if (discrim == NULL)
return -1;
@@ -6906,7 +6886,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
else if (is_dynamic_field (type, f))
{
if (dval0 == NULL)
- dval = value_from_contents_and_address (rtype, valaddr, address);
+ dval = value_from_contents_and_address (rtype, valaddr, 0, address);
else
dval = dval0;
@@ -6955,7 +6935,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
off = TYPE_FIELD_BITPOS (rtype, variant_field);
if (dval0 == NULL)
- dval = value_from_contents_and_address (rtype, valaddr, address);
+ dval = value_from_contents_and_address (rtype, valaddr, 0, address);
else
dval = dval0;
@@ -7096,7 +7076,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
return type;
if (dval0 == NULL)
- dval = value_from_contents_and_address (type, valaddr, address);
+ dval = value_from_contents_and_address (type, valaddr, 0, address);
else
dval = dval0;
@@ -7533,7 +7513,7 @@ ada_to_fixed_value_create (struct type *type0, CORE_ADDR address,
if (type == type0 && val0 != NULL)
return val0;
else
- return value_from_contents_and_address (type, 0, address);
+ return value_from_contents_and_address (type, 0, 0, address);
}
/* A value representing VAL, but with a standard (static-sized) type
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index 562a867..440558c 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -257,10 +257,6 @@ extern int ada_value_print (struct value *, struct ui_file *,
/* Defined in ada-lang.c */
-extern struct value *value_from_contents_and_address (struct type *,
- const gdb_byte *,
- CORE_ADDR);
-
extern void ada_emit_char (int, struct ui_file *, int, int);
extern void ada_printchar (int, struct ui_file *);
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 37e944b..3167dcd 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -501,7 +501,7 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
get_tcb_types_info (&atcb_type, &atcb_common_type, &atcb_ll_type,
&atcb_call_type, &fieldno);
- tcb_value = value_from_contents_and_address (atcb_type, NULL, task_id);
+ tcb_value = value_from_contents_and_address (atcb_type, NULL, 0, task_id);
common_value = value_field (tcb_value, fieldno.common);
/* Fill in the task_id. */
@@ -598,7 +598,7 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
if (call != 0)
{
call_val =
- value_from_contents_and_address (atcb_call_type, NULL, call);
+ value_from_contents_and_address (atcb_call_type, NULL, 0, call);
task_info->caller_task =
value_as_address (value_field (call_val, fieldno.call_self));
}
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index cc8352f..808a8f5 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -679,7 +679,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
int retn;
struct value *mark = value_mark ();
struct value *val;
- val = value_from_contents_and_address (type, valaddr, address);
+ val = value_from_contents_and_address (type, valaddr, 0, address);
val = ada_coerce_to_simple_array_ptr (val);
if (val == NULL)
{
@@ -710,7 +710,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
if (ada_is_tag_type (type))
{
struct value *val =
- value_from_contents_and_address (type, valaddr, address);
+ value_from_contents_and_address (type, valaddr, 0, address);
const char *name = ada_tag_name (val);
if (name != NULL)
fprintf_filtered (stream, " (%s)", name);
@@ -733,7 +733,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
else if (ada_is_vax_floating_type (type))
{
struct value *val =
- value_from_contents_and_address (type, valaddr, address);
+ value_from_contents_and_address (type, valaddr, 0, address);
struct value *func = ada_vax_float_print_function (type);
if (func != 0)
{
@@ -768,7 +768,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
code regardless of lengths; I'm just avoiding a cast. */
struct value *v = value_cast (target_type,
value_from_contents_and_address
- (type, valaddr, 0));
+ (type, valaddr, 0, 0));
return ada_val_print_1 (target_type, value_contents (v), 0, 0,
stream, recurse + 1, options);
}
@@ -948,7 +948,7 @@ ada_value_print (struct value *val0, struct ui_file *stream,
struct type *type =
ada_to_fixed_type (value_type (val0), valaddr, address, NULL, 1);
struct value *val =
- value_from_contents_and_address (type, valaddr, address);
+ value_from_contents_and_address (type, valaddr, 0, address);
struct value_print_options opts;
/* If it is a pointer, indicate what it points to. */
diff --git a/gdb/value.c b/gdb/value.c
index 695aa33..c4181d5 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1686,6 +1686,28 @@ value_from_string (char *ptr)
return val;
}
+/* Return a new value constructed from some bytes. TYPE is the type
+ of the object. VALADDR is a pointer to the base of the enclosing
+ object. If VALADDR is NULL, the value is marked as lazy.
+ EMBEDDED_OFFSET is the offset into VALADDR of the bytes making up
+ the new object. ADDRESS is the inferior address of the object. */
+
+struct value *
+value_from_contents_and_address (struct type *type, const gdb_byte *valaddr,
+ int embedded_offset, CORE_ADDR address)
+{
+ struct value *v = allocate_value (type);
+ if (valaddr == NULL)
+ set_value_lazy (v, 1);
+ else
+ memcpy (value_contents_raw (v), valaddr + embedded_offset,
+ TYPE_LENGTH (type));
+ VALUE_ADDRESS (v) = address;
+ if (address != 0)
+ VALUE_LVAL (v) = lval_memory;
+ return v;
+}
+
struct value *
value_from_double (struct type *type, DOUBLEST num)
{
diff --git a/gdb/value.h b/gdb/value.h
index 65fea99..53b6af5 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -289,6 +289,10 @@ 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);
+extern struct value *value_from_contents_and_address (struct type *,
+ const gdb_byte *,
+ int, CORE_ADDR);
+
extern struct value *default_value_from_register (struct type *type,
int regnum,
struct frame_info *frame);