Re: [PATCH PR gdb/22736] [aarch64] gdb crashes on a conditional breakpoint with cast return type

Joel Brobecker
2018-03-02T03:32:12Z

On Thu, Mar 01, 2018 at 05:03:44PM +0000, Alan Hayward wrote:
> On aarch64, the (int) casting in the following causes a gdb segfault:
> $ ./gdb ./gdb
> (gdb) b dwarf2_physname if (int)strcmp (name, "another_thread_local") == 0
> (gdb) run a.out // use any a.out
>
> This is due to getting a null pointer from TYPE_TARGET_TYPE, and then
> using it for language_pass_by_reference().
>
> Fixed by adding a null check, similar to other occurrences in gdb.
>
> Tested on aarch64 with make check using unix, native_gdbserver.
>
> Alan.
>
>
> 2018-03-01 Alan Hayward <alan.hayward@arm.com>
>
> * aarch64-tdep.c (aarch64_push_dummy_call): Check for null
> return_type.

The patch looks good to me, but do you think you could add a test
for it? Intuitively, I think this should be fairly easily doable,
but can you confirm?

> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index f08945ea07101e1cd7906ca640c023ac7d189dd9..ef982c78fe64ceef3c7c378fd22d76604bf81c31 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -1382,7 +1382,7 @@ aarch64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
> struct aarch64_call_info info;
> struct type *func_type;
> struct type *return_type;
> - int lang_struct_return;
> + int lang_struct_return = 0;
>
> memset (&info, 0, sizeof (info));
>
> @@ -1424,7 +1424,8 @@ aarch64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
> 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);
> + if (return_type != nullptr)
> + lang_struct_return = language_pass_by_reference (return_type);
>
> /* Set the return address. For the AArch64, the return breakpoint
> is always at BP_ADDR. */
>

--
Joel