Re: [PATCH 04/18] gdbserver crash running gdb.threads/non-ldr-exc-1.exp

Yao Qi
2015-10-26T10:55:45Z

Pedro Alves <palves@redhat.com> writes:

> diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
> index e25b7c7..ec52f84 100644
> --- a/gdb/gdbserver/server.c
> +++ b/gdb/gdbserver/server.c
> @@ -1971,6 +1971,27 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
>
> if (strcmp ("qSymbol::", own_buf) == 0)
> {
> + struct thread_info *save_thread = current_thread;
> +
> + /* For qSymbol, GDB only changes the current thread if the
> + previous current thread was of a different process. So if
> + the previous thread is gone, we need to pick another one of
> + the same process. This can happen e.g., if we followed an
> + exec in a non-leader thread. */
> + if (current_thread == NULL)
> + {
> + current_thread = find_any_thread_of_pid (ptid_get_pid (general_thread));
> +

Nit, this line is too long. Patch looks good to me, otherwise.

I do something similar in AArch64 GDBserver backend to fix the crash.
Could you include this patch in your series if it is OK to you? My
patch depends on your patch 04/18.
Note that I didn't add "set_general_process" as you suggested, because I
am not 100% sure the rules of switching current_thread.

--
Yao (齐尧)
From 58ad7851575c5b9c1a2343e6de3dfb4b7b51a6c6 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Fri, 23 Oct 2015 14:00:50 +0100
Subject: [PATCH] [aarch64] gdbserver crash running
gdb.threads/no-unwaited-for-left.exp

This fixes an aarch64 GDBserver crash when running
gdb.threads/no-unwaited-for-left.exp. The problem is that current_thread
is NULL when GDBserver checks whether is 64-bit or not. The fix is
straightforward, if current_thread is NULL, find other thread in the
same process. If none is found, assume the thread is 64-bit.

gdb/gdbserver:

2015-10-26 Yao Qi <yao.qi@linaro.org>

* linux-aarch64-low.c (is_64bit_tdesc): If current_thread is NULL,
select another thread of the same process, otherwise, select
current_thread.

diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index cb49a04..54d8891 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -81,7 +81,24 @@ struct arch_process_info
static int
is_64bit_tdesc (void)
{
- struct regcache *regcache = get_thread_regcache (current_thread, 0);
+ struct thread_info *thread;
+ struct regcache *regcache;
+
+ /* If the current thread is gone, pick another one of the same
+ process. */
+ if (current_thread == NULL)
+ thread = find_any_thread_of_pid (ptid_get_pid (general_thread));
+ else
+ thread = current_thread;
+
+ if (thread == NULL)
+ {
+ /* If we didn't find a thread, assume the inferior will be an
+ aarch64 process. */
+ return 1;
+ }
+
+ regcache = get_thread_regcache (thread, 0);

return register_size (regcache->tdesc, 0) == 8;
}