Big-endian targets: Don't ignore offset into DW_OP_implicit_value

When a variable's location is expressed as DW_OP_implicit_value, but the
given value is longer than needed, which bytes should be used?  GDB's
current logic was introduced with a patch from 2011 and uses the "least
significant" bytes:

  https://sourceware.org/ml/gdb-patches/2011-08/msg00123.html

Now consider a sub-value from such a location at a given offset, accessed
through DW_OP_implicit_pointer.  Which bytes should be used for that?  The
patch above *always* uses the last bytes on big-endian targets, ignoring
the offset.

E.g., given the code snippet

  const char foo[] = "Hello, world!";
  const char *a = &foo[0];
  const char *b = &foo[7];

assume that `foo' is described as DW_OP_implicit_value and `a' and `b'
each as DW_OP_implicit_pointer into that value.  Then with current GDB
`*a' and `*b' yield the same result -- the string's zero terminator.

This patch basically reverts the portion of the patch above that deals
with DW_OP_implicit_value.  This fixes the offset handling and also goes
back to dropping the last instead of the first bytes on big-endian targets
if the implicit value is longer than needed.  The latter aspect of the
change probably doesn't matter for actual programs, but simplifies the
logic.

The patch also cleans up the original code a bit and adds appropriate test
cases.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-op-stack-value.exp: Adjust expected result of
	taking a 2-byte value out of a 4-byte DWARF implicit value on
	big-endian targets.
	* gdb.dwarf2/nonvar-access.exp: Add more comments to existing
	logic.  Add test cases for DW_OP_implicit.

gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): For
	DWARF_VALUE_LITERAL, no longer ignore the offset on big-endian
	targets.  And if the implicit value is longer than needed, extract
	the first bytes instead of the "least significant" ones.
This commit is contained in:
Andreas Arnez
2017-02-01 16:59:00 +01:00
parent 787f00256b
commit 7346ef59bb
5 changed files with 95 additions and 19 deletions

View File

@@ -2442,28 +2442,15 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
case DWARF_VALUE_LITERAL:
{
bfd_byte *contents;
const bfd_byte *ldata;
size_t n = ctx.len;
size_t n = TYPE_LENGTH (type);
if (byte_offset + TYPE_LENGTH (type) > n)
if (byte_offset + n > ctx.len)
invalid_synthetic_pointer ();
free_values.free_to_mark ();
retval = allocate_value (type);
contents = value_contents_raw (retval);
ldata = ctx.data + byte_offset;
n -= byte_offset;
if (n > TYPE_LENGTH (type))
{
struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
ldata += n - TYPE_LENGTH (type);
n = TYPE_LENGTH (type);
}
memcpy (contents, ldata, n);
memcpy (contents, ctx.data + byte_offset, n);
}
break;