Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFA: move value_from_contents_and_address to value.c
@ 2008-11-21 17:07 Tom Tromey
  2008-11-22 12:00 ` Michael Snyder
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Tom Tromey @ 2008-11-21 17:07 UTC (permalink / raw)
  To: gdb-patches

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);


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFA: move value_from_contents_and_address to value.c
  2008-11-21 17:07 RFA: move value_from_contents_and_address to value.c Tom Tromey
@ 2008-11-22 12:00 ` Michael Snyder
  2008-11-22 18:01 ` Joel Brobecker
  2008-11-25 18:23 ` Jerome Guitton
  2 siblings, 0 replies; 9+ messages in thread
From: Michael Snyder @ 2008-11-22 12:00 UTC (permalink / raw)
  To: tromey; +Cc: gdb-patches

Tom Tromey wrote:
> 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?

Joel or Robert will have to speak on behalf of Ada,
but I think it's good.

> 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);


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFA: move value_from_contents_and_address to value.c
  2008-11-21 17:07 RFA: move value_from_contents_and_address to value.c Tom Tromey
  2008-11-22 12:00 ` Michael Snyder
@ 2008-11-22 18:01 ` Joel Brobecker
  2008-11-23 22:12   ` Tom Tromey
  2008-11-24 23:16   ` Tom Tromey
  2008-11-25 18:23 ` Jerome Guitton
  2 siblings, 2 replies; 9+ messages in thread
From: Joel Brobecker @ 2008-11-22 18:01 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Generally speaking, I'm very happy to see the function being moved
out of ada-lang.c.

> +/* 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)

I'm wondering whether the offset parameter is really necessary? Would it
be worse to call this function with valaddr+embedded_offset rather
than passing two arguments?

-- 
Joel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFA: move value_from_contents_and_address to value.c
  2008-11-22 18:01 ` Joel Brobecker
@ 2008-11-23 22:12   ` Tom Tromey
  2008-11-24 23:16   ` Tom Tromey
  1 sibling, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2008-11-23 22:12 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

Joel> I'm wondering whether the offset parameter is really necessary? Would it
Joel> be worse to call this function with valaddr+embedded_offset rather
Joel> than passing two arguments?

I will remove it and resubmit.

Tom


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFA: move value_from_contents_and_address to value.c
  2008-11-22 18:01 ` Joel Brobecker
  2008-11-23 22:12   ` Tom Tromey
@ 2008-11-24 23:16   ` Tom Tromey
  2008-11-25 11:49     ` Joel Brobecker
  1 sibling, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2008-11-24 23:16 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

Joel> I'm wondering whether the offset parameter is really necessary? Would it
Joel> be worse to call this function with valaddr+embedded_offset rather
Joel> than passing two arguments?

Here is an updated patch which dispenses with this argument.

Built and regtested on x86-64 (compile farm).

Ok?

Tom

2008-11-24  Tom Tromey  <tromey@redhat.com>

	* ada-lang.c (value_from_contents_and_address): Move...
	* value.c: ... here.
	* ada-lang.h (value_from_contents_and_address): Move
	declaration...
	* value.h: ... here.

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f92d23b..d27416f 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.  */
 
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/value.c b/gdb/value.c
index 695aa33..03385f3 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1686,6 +1686,26 @@ value_from_string (char *ptr)
   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.  */
+
+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;
+}
+
 struct value *
 value_from_double (struct type *type, DOUBLEST num)
 {
diff --git a/gdb/value.h b/gdb/value.h
index 65fea99..3e924cc 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 *,
+                                                      CORE_ADDR);
+
 extern struct value *default_value_from_register (struct type *type,
 						  int regnum,
 						  struct frame_info *frame);


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFA: move value_from_contents_and_address to value.c
  2008-11-24 23:16   ` Tom Tromey
@ 2008-11-25 11:49     ` Joel Brobecker
  2008-11-25 17:06       ` Tom Tromey
  0 siblings, 1 reply; 9+ messages in thread
From: Joel Brobecker @ 2008-11-25 11:49 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> 2008-11-24  Tom Tromey  <tromey@redhat.com>
> 
> 	* ada-lang.c (value_from_contents_and_address): Move...
> 	* value.c: ... here.
> 	* ada-lang.h (value_from_contents_and_address): Move
> 	declaration...
> 	* value.h: ... here.

Looks great to me.

Just one tiny little remark, and I know it's our fault (at AdaCore).
If you can fix it before checking in, then great. Otherwise, I can
do it after you've checked the change in.

> +struct value *
> +value_from_contents_and_address (struct type *type,
> +				 const gdb_byte *valaddr,
> +                                 CORE_ADDR address)

There is a formatting issue in the third line, due to the use of
spaces instead of tabs. I try to be super careful, now, but I can't
seem to be able to find a convenient way of configuring my editor
(vim) for that.

> +extern struct value *value_from_contents_and_address (struct type *,
> +						      const gdb_byte *,
> +                                                      CORE_ADDR);

Same here.

Thanks!
-- 
Joel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFA: move value_from_contents_and_address to value.c
  2008-11-25 11:49     ` Joel Brobecker
@ 2008-11-25 17:06       ` Tom Tromey
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2008-11-25 17:06 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

>> +struct value *
>> +value_from_contents_and_address (struct type *type,
>> +				 const gdb_byte *valaddr,
>> +                                 CORE_ADDR address)

Joel> There is a formatting issue in the third line, due to the use of
Joel> spaces instead of tabs. I try to be super careful, now, but I can't
Joel> seem to be able to find a convenient way of configuring my editor
Joel> (vim) for that.

I got a little confused by this, because the third line above does
have tabs.  I assume you meant the fourth line, so I'm checking in the
version with tabs on both continuation lines.

FWIW gdbint.texinfo does not mention tabs-vs-spaces.

Tom


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFA: move value_from_contents_and_address to value.c
  2008-11-21 17:07 RFA: move value_from_contents_and_address to value.c Tom Tromey
  2008-11-22 12:00 ` Michael Snyder
  2008-11-22 18:01 ` Joel Brobecker
@ 2008-11-25 18:23 ` Jerome Guitton
  2008-11-25 18:38   ` Jerome Guitton
  2 siblings, 1 reply; 9+ messages in thread
From: Jerome Guitton @ 2008-11-25 18:23 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Tom Tromey (tromey@redhat.com):

> 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.

By the way, I think there is a bug in the way we implemented it in
ada-lang.c.  If I read the code correctly,
value_from_contents_and_address returns a not_lval lazy value when
valaddr is null. Not sure what we were trying to do, but this is
certainly wrong... I'll have a look.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFA: move value_from_contents_and_address to value.c
  2008-11-25 18:23 ` Jerome Guitton
@ 2008-11-25 18:38   ` Jerome Guitton
  0 siblings, 0 replies; 9+ messages in thread
From: Jerome Guitton @ 2008-11-25 18:38 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Jerome Guitton (guitton@adacore.com):

> By the way, I think there is a bug in the way we implemented it in
> ada-lang.c.  If I read the code correctly,
> value_from_contents_and_address returns a not_lval lazy value when
> valaddr is null. Not sure what we were trying to do, but this is
> certainly wrong... I'll have a look.

I meant: "when valaddr is null *and* address is 0".

Anyway, this can be fixed after of your changes.  I'll take care of
it.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-11-25 11:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-21 17:07 RFA: move value_from_contents_and_address to value.c Tom Tromey
2008-11-22 12:00 ` Michael Snyder
2008-11-22 18:01 ` Joel Brobecker
2008-11-23 22:12   ` Tom Tromey
2008-11-24 23:16   ` Tom Tromey
2008-11-25 11:49     ` Joel Brobecker
2008-11-25 17:06       ` Tom Tromey
2008-11-25 18:23 ` Jerome Guitton
2008-11-25 18:38   ` Jerome Guitton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox