This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [rfa/gdbserver] Updated: Fix crash in thread_db_get_tls_address


Pedro Alves wrote:
> A Friday 03 April 2009 20:20:09, Ulrich Weigand escreveu:
> > Pedro Alves wrote:
> > 
> > > The qGetTLSAddr packet takes an explicit thread id, so in this
> > > case, it may be that the current process isn't the
> > > correct one.  I think in this case the best would be to
> > > inferior.c:get_thread_process and use that, like:
> 
>    ^ export
> 
> > > 
> > >   if (!get_thread_process (thread)->all_symbols_looked_up)
> > >     return TD_ERR;
> > 
> > That function is currently static to inferior.c; I guess it
> > should be exported?
> 
> Yes.  That's what I meant, but fingers slipped.  :-)
> 
> > > Alternatively you could make sure you call current_process (),
> > > after temporarily   having switched the current inferior, like
> > > we do a bit below.
> > 
> > Hmm, I want to guard against find_one_thread blowing up due to
> > a NULL proc->thread_agent -- but "proc" is always refering to
> > current_process () as well.  This is probably incorrect too,
> > and find_one_thread ought to use get_thread_process?
> 
> Indeed.

OK, here's the version I've just committed.  Retested on powerpc64-linux
(64-bit and 32-bit) with local gdbserver.

Thanks,
Ulrich

ChangeLog:

	* inferiors.c (get_thread_process): Make global.
	* server.h (get_thread_process): Add prototype.
	* thread-db.c (find_one_thread): Use get_thread_process
	instead of current_process.
	(thread_db_get_tls_address): Do not crash if called when
	thread layer is not yet initialized.


Index: gdb/gdbserver/inferiors.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/inferiors.c,v
retrieving revision 1.19
diff -u -p -r1.19 inferiors.c
--- gdb/gdbserver/inferiors.c	1 Apr 2009 22:50:24 -0000	1.19
+++ gdb/gdbserver/inferiors.c	3 Apr 2009 19:47:11 -0000
@@ -442,7 +442,7 @@ find_process_pid (int pid)
     find_inferior_id (&all_processes, pid_to_ptid (pid));
 }
 
-static struct process_info *
+struct process_info *
 get_thread_process (struct thread_info *thread)
 {
   int pid = ptid_get_pid (thread->entry.id);
Index: gdb/gdbserver/server.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.h,v
retrieving revision 1.55
diff -u -p -r1.55 server.h
--- gdb/gdbserver/server.h	1 Apr 2009 22:50:24 -0000	1.55
+++ gdb/gdbserver/server.h	3 Apr 2009 19:47:11 -0000
@@ -201,6 +201,7 @@ struct process_info
    no current thread selected.  */
 
 struct process_info *current_process (void);
+struct process_info *get_thread_process (struct thread_info *);
 
 #include "regcache.h"
 #include "gdb/signals.h"
Index: gdb/gdbserver/thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/thread-db.c,v
retrieving revision 1.22
diff -u -p -r1.22 thread-db.c
--- gdb/gdbserver/thread-db.c	1 Apr 2009 22:50:24 -0000	1.22
+++ gdb/gdbserver/thread-db.c	3 Apr 2009 19:47:11 -0000
@@ -233,7 +233,7 @@ find_one_thread (ptid_t ptid)
   td_err_e err;
   struct thread_info *inferior;
   struct lwp_info *lwp;
-  struct process_info_private *proc = current_process()->private;
+  struct process_info_private *proc;
   int lwpid = ptid_get_lwp (ptid);
 
   inferior = (struct thread_info *) find_inferior_id (&all_threads, ptid);
@@ -242,6 +242,7 @@ find_one_thread (ptid_t ptid)
     return 1;
 
   /* Get information about this thread.  */
+  proc = get_thread_process (inferior)->private;
   err = td_ta_map_lwp2thr (proc->thread_agent, lwpid, &th);
   if (err != TD_OK)
     error ("Cannot get thread handle for LWP %d: %s",
@@ -382,6 +383,10 @@ thread_db_get_tls_address (struct thread
   struct lwp_info *lwp;
   struct thread_info *saved_inferior;
 
+  /* If the thread layer is not (yet) initialized, fail.  */
+  if (!get_thread_process (thread)->all_symbols_looked_up)
+    return TD_ERR;
+
   lwp = get_thread_lwp (thread);
   if (!lwp->thread_known)
     find_one_thread (lwp->head.id);


-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]