aboutsummaryrefslogtreecommitdiff
path: root/gdb/aarch64-tdep.c
diff options
context:
space:
mode:
authorAlan Hayward <alan.hayward@arm.com>2018-10-11 14:47:30 +0100
committerAlan Hayward <alan.hayward@arm.com>2018-11-16 13:45:38 +0000
commit38a72da0f1d968432ae6a2a9697ba55932dc075e (patch)
treeb25e8c746263a3201b2a32bf60f2bc094eb8f46f /gdb/aarch64-tdep.c
parentcf84fa6bcf514157df8343d32885050bafc396f7 (diff)
downloadgdb-38a72da0f1d968432ae6a2a9697ba55932dc075e.zip
gdb-38a72da0f1d968432ae6a2a9697ba55932dc075e.tar.gz
gdb-38a72da0f1d968432ae6a2a9697ba55932dc075e.tar.bz2
Aarch64: Fix segfault when casting dummy calls
The following will segfault on aarch64 if foo is in another object, was compiled as c++ and has no debug symbols: (gdb) p (int)foo() This is because aarch64_push_dummy_call determines the return type of the function and then does not check for null pointer. A null pointer for the return type means the call has no debug information. For the code to get here, then the call must have been cast, otherwise we'd error out sooner. In the case of a no-debug-info call cast, the return type is the type the user had cast the call to, but we do not have that information available here. However, aarch64_push_dummy_call only requires the return type in order to calculate lang_struct_return. This information is available in the return_method enum. The fix is to simply use this instead. Adds testcase to check calls across objects, with all combinations of c, c++, debug and no debug. gdb/ChangeLog: PR gdb/22736: * aarch64-tdep.c (aarch64_push_dummy_call): Remove lang_struct_return code. gdb/testsuite/ChangeLog: PR gdb/22736: * gdb.cp/infcall-nodebug-lib.c: New test. * gdb.cp/infcall-nodebug-main.c: New test. * gdb.cp/infcall-nodebug.exp: New file.
Diffstat (limited to 'gdb/aarch64-tdep.c')
-rw-r--r--gdb/aarch64-tdep.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 7a0d5b3..ae56c9c 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -1520,9 +1520,6 @@ aarch64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
{
int argnum;
struct aarch64_call_info info;
- struct type *func_type;
- struct type *return_type;
- int lang_struct_return;
memset (&info, 0, sizeof (info));
@@ -1544,42 +1541,21 @@ aarch64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
If the language code decides to pass in memory we want to move
the pointer inserted as the initial argument from the argument
list and into X8, the conventional AArch64 struct return pointer
- register.
-
- This is slightly awkward, ideally the flag "lang_struct_return"
- would be passed to the targets implementation of push_dummy_call.
- Rather that change the target interface we call the language code
- directly ourselves. */
-
- func_type = check_typedef (value_type (function));
-
- /* Dereference function pointer types. */
- if (TYPE_CODE (func_type) == TYPE_CODE_PTR)
- func_type = TYPE_TARGET_TYPE (func_type);
-
- gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC
- || TYPE_CODE (func_type) == TYPE_CODE_METHOD);
-
- /* If language_pass_by_reference () returned true we will have been
- given an additional initial argument, a hidden pointer to the
- return slot in memory. */
- return_type = TYPE_TARGET_TYPE (func_type);
- lang_struct_return = language_pass_by_reference (return_type);
+ register. */
/* Set the return address. For the AArch64, the return breakpoint
is always at BP_ADDR. */
regcache_cooked_write_unsigned (regcache, AARCH64_LR_REGNUM, bp_addr);
- /* If we were given an initial argument for the return slot because
- lang_struct_return was true, lose it. */
- if (lang_struct_return)
+ /* If we were given an initial argument for the return slot, lose it. */
+ if (return_method == return_method_hidden_param)
{
args++;
nargs--;
}
/* The struct_return pointer occupies X8. */
- if (return_method == return_method_struct || lang_struct_return)
+ if (return_method != return_method_normal)
{
if (aarch64_debug)
{