Patchwork Fix assertion failure in coerce_unspec_val_to_type

login
register
mail settings
Submitter Tom Tromey
Date May 14, 2019, 7:29 p.m.
Message ID <20190514192939.4138-1-tromey@adacore.com>
Download mbox | patch
Permalink /patch/32687/
State New
Headers show

Comments

Tom Tromey - May 14, 2019, 7:29 p.m.
coerce_unspec_val_to_type does:

      set_value_address (result, value_address (val));

However, this is only valid for lval_memory.  This patch changes this
code to only set the address for lval_memory values.

This seems like an ordinary oversight in coerce_unspec_val_to_type,
and a test case would be difficult to write, so I'm submitting it
without a test case.

Tested on x86-64 Fedora 29; plus using an Ada program that exhibits
the bug (but which cannot be shared).

gdb/ChangeLog
2019-05-14  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (coerce_unspec_val_to_type): Only set address when
	value is not lval_memory.
---
 gdb/ChangeLog  | 5 +++++
 gdb/ada-lang.c | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)
Joel Brobecker - May 14, 2019, 8:19 p.m.
> coerce_unspec_val_to_type does:
> 
>       set_value_address (result, value_address (val));
> 
> However, this is only valid for lval_memory.  This patch changes this
> code to only set the address for lval_memory values.
> 
> This seems like an ordinary oversight in coerce_unspec_val_to_type,
> and a test case would be difficult to write, so I'm submitting it
> without a test case.
> 
> Tested on x86-64 Fedora 29; plus using an Ada program that exhibits
> the bug (but which cannot be shared).
> 
> gdb/ChangeLog
> 2019-05-14  Tom Tromey  <tromey@adacore.com>
> 
> 	* ada-lang.c (coerce_unspec_val_to_type): Only set address when
> 	value is not lval_memory.

This is OK.

Tom and I discussed it internally at AdaCore, and one of the questions
that Tom answered for me was the fact that it's OK to only handle
the case where the value is an lval_memory. For the other cases,
the value's location is handled a little earlier in
set_value_component_location.

> ---
>  gdb/ChangeLog  | 5 +++++
>  gdb/ada-lang.c | 3 ++-
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index dee3a83f98c..23197f60340 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -672,7 +672,8 @@ coerce_unspec_val_to_type (struct value *val, struct type *type)
>        set_value_component_location (result, val);
>        set_value_bitsize (result, value_bitsize (val));
>        set_value_bitpos (result, value_bitpos (val));
> -      set_value_address (result, value_address (val));
> +      if (VALUE_LVAL (result) == lval_memory)
> +	set_value_address (result, value_address (val));
>        return result;
>      }
>  }
> -- 
> 2.20.1

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index dee3a83f98c..23197f60340 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -672,7 +672,8 @@  coerce_unspec_val_to_type (struct value *val, struct type *type)
       set_value_component_location (result, val);
       set_value_bitsize (result, value_bitsize (val));
       set_value_bitpos (result, value_bitpos (val));
-      set_value_address (result, value_address (val));
+      if (VALUE_LVAL (result) == lval_memory)
+	set_value_address (result, value_address (val));
       return result;
     }
 }