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

Message ID 86mvv52920.fsf@gmail.com
State New, archived
Headers

Commit Message

Yao Qi Oct. 26, 2015, 10:55 a.m. UTC
  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.
  

Patch

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;
 }