From 911627e7b1bc682a18ac5a976eb33cd87d73578f Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 7 Sep 2022 09:52:44 -0600 Subject: Fix inferior calls with variably-sized return type This patch updates the gdbarch_return_value_as_value implementations to work correctly with variably-sized return types. --- gdb/sparc-tdep.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'gdb/sparc-tdep.c') diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c index 91cf391..55c8434 100644 --- a/gdb/sparc-tdep.c +++ b/gdb/sparc-tdep.c @@ -1500,13 +1500,6 @@ sparc32_return_value (struct gdbarch *gdbarch, struct value *function, { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - gdb_byte *readbuf = nullptr; - if (read_value != nullptr) - { - *read_value = allocate_value (type); - readbuf = value_contents_raw (*read_value).data (); - } - /* The psABI says that "...every stack frame reserves the word at %fp+64. If a function returns a structure, union, or quad-precision value, this word should hold the address of the @@ -1519,11 +1512,11 @@ sparc32_return_value (struct gdbarch *gdbarch, struct value *function, ULONGEST sp; CORE_ADDR addr; - if (readbuf) + if (read_value != nullptr) { regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp); addr = read_memory_unsigned_integer (sp + 64, 4, byte_order); - read_memory (addr, readbuf, type->length ()); + *read_value = value_at_non_lval (type, addr); } if (writebuf) { @@ -1535,8 +1528,12 @@ sparc32_return_value (struct gdbarch *gdbarch, struct value *function, return RETURN_VALUE_ABI_PRESERVES_ADDRESS; } - if (readbuf) - sparc32_extract_return_value (type, regcache, readbuf); + if (read_value != nullptr) + { + *read_value = allocate_value (type); + gdb_byte *readbuf = value_contents_raw (*read_value).data (); + sparc32_extract_return_value (type, regcache, readbuf); + } if (writebuf) sparc32_store_return_value (type, regcache, writebuf); -- cgit v1.1