Remove setting value address for reference entry value target data value.
authorJan Kratochvil <jan.kratochvil@redhat.com>
Tue, 22 Jul 2014 20:15:27 +0000 (22:15 +0200)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Tue, 22 Jul 2014 20:15:27 +0000 (22:15 +0200)
commit45326f6fbe28ef5bac22dac447a4181c44cb945a
tree2364904f361565ce16f162838c8dffa6d32db41d
parente214cf6c2e05bcfc85dc6f335d8ffdc3629cf0cf
Remove setting value address for reference entry value target data value.

I cannot reproduce any wrong case having the code removed.

I just do not find it correct to have it disabled.  But at the same time I do
like much / I do not find correct the code myself.  It is a bit problematic to
have struct value describing a memory content which is no longer present
there.

What happens there:
------------------------------------------------------------------------------
volatile int vv;
static __attribute__((noinline)) int
bar (int &ref) {
  ref = 20;
  vv++; /* break-here */
  return ref;
}
int main (void) {
  int var = 10;
  return bar (var);
}
------------------------------------------------------------------------------
 <4><c7>: Abbrev Number: 13 (DW_TAG_GNU_call_site_parameter)
    <c8>   DW_AT_location    : 1 byte block: 55         (DW_OP_reg5 (rdi))
    <ca>   DW_AT_GNU_call_site_value: 2 byte block: 91 74       (DW_OP_fbreg: -12)
    <cd>   DW_AT_GNU_call_site_data_value: 1 byte block: 3a     (DW_OP_lit10)
------------------------------------------------------------------------------
gdb -ex 'b value_addr' -ex r --args ../gdb ./1 -ex 'watch vv' -ex r -ex 'p &ref@entry'
->
6    return ref;
bar (ref=@0x7fffffffd944: 20, ref@entry=@0x7fffffffd944: 10) at 1.C:25
------------------------------------------------------------------------------
At /* break-here */ struct value variable 'ref' is TYPE_CODE_REF.

With FSF GDB HEAD:
(gdb) x/gx arg1.contents
0x6004000a4ad0: 0x00007fffffffd944
(gdb) p ((struct value *)arg1.location.computed.closure).lval
$1 = lval_memory
(gdb) p/x ((struct value *)arg1.location.computed.closure).location.address
$3 = 0x7fffffffd944

With your #if0-ed code:
(gdb) x/gx arg1.contents
0x6004000a4ad0: 0x00007fffffffd944
(gdb) p ((struct value *)arg1.location.computed.closure).lval
$8 = not_lval
(gdb) p/x ((struct value *)arg1.location.computed.closure).location.address
$9 = 0x0

I do not see how to access
        ((struct value *)arg1.location.computed.closure).location.address
from GDB CLI.  Trying
(gdb) p &ref@entry
will invoke value_addr()'s:
  if (TYPE_CODE (type) == TYPE_CODE_REF)
      /* Copy the value, but change the type from (T&) to (T*).  We
         keep the same location information, which is efficient, and
         allows &(&X) to get the location containing the reference.  */
and therefore the address gets fetched already from
  arg1.contents
and not from
  ((struct value *)arg1.location.computed.closure).location.address
.

And for any other type than TYPE_CODE_REF this code you removed does not get
executed at all.  This DW_AT_GNU_call_site_data_value DWARF was meant
primarily for Fortran but with -O0 entry values do not get produced
and with -Og and higher Fortran always optimizes out the passing by reference.

If you do not like the removed code there I am OK with removing it as I do not
know how to make it's use reproducible for user anyway.  In the worst case
- if there really is some way how to exploit it - one should just get
  Attempt to take address of value not located in memory.
instead of some wrong value and it may be easy to fix then.

gdb/
2014-07-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

* dwarf2loc.c (value_of_dwarf_reg_entry): Remove setting value address
for reference entry value target data value.

Message-ID: <20140720150727.GA18488@host2.jankratochvil.net>
gdb/ChangeLog
gdb/dwarf2loc.c
This page took 0.027108 seconds and 4 git commands to generate.