Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] gdbserver: Add support for qGetTLSAddr packet
@ 2004-12-06 22:37 Kevin Buettner
  2004-12-06 23:48 ` Andreas Schwab
  2005-02-25 15:52 ` Daniel Jacobowitz
  0 siblings, 2 replies; 6+ messages in thread
From: Kevin Buettner @ 2004-12-06 22:37 UTC (permalink / raw)
  To: gdb-patches

The patch below adds qGetTLSAddr packet support to gdbserver.

I wrote this to demonstrate / test the support that I've added on the
GDB side.  I suspect some configury tweaking may be needed to test for
the existence of td_thr_tls_get_addr() in libthread_db.c.  (If it
doesn't exist, then get_thread_local_addr() should be ifdef'd to return
a 0 status.)

If it's otherwise okay, I'm willing to make the necessary configury
changes.  If it's not okay for some other reason, I'd like to address
that first...

Here are pointers to the proposal and related patches:

  http://sources.redhat.com/ml/gdb/2004-11/msg00189.html
  http://sources.redhat.com/ml/gdb-patches/2004-12/msg00168.html
  http://sources.redhat.com/ml/gdb-patches/2004-12/msg00169.html
  http://sources.redhat.com/ml/gdb-patches/2004-12/msg00170.html

Kevin

	* Makefile.in (server.o): Cause USE_THREAD_DB to be defined as
	appropriate.
	* remote-utils.c (decode_qGetTLSAddr_args, encode_qGetTLSAddr_result):
	New functions.
	* server.c (handle_query): Add support for qGetTLSAddr packet.
	* server.h (decode_qGetTLSAddr_args, encode_qGetTLSAddr_result)
	(get_thread_local_addr): Declare.
	* thread-db.c (get_thread_local_addr): New function.

Index: gdbserver/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/Makefile.in,v
retrieving revision 1.27
diff -u -p -r1.27 Makefile.in
--- gdbserver/Makefile.in	16 Oct 2004 16:18:54 -0000	1.27
+++ gdbserver/Makefile.in	6 Dec 2004 21:58:56 -0000
@@ -246,6 +246,8 @@ proc-service.o: proc-service.c $(server_
 regcache.o: regcache.c $(server_h) $(regdef_h)
 remote-utils.o: remote-utils.c terminal.h $(server_h)
 server.o: server.c $(server_h)
+	$(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< @USE_THREAD_DB@
+
 target.o: target.c $(server_h)
 thread-db.o: thread-db.c $(server_h) $(gdb_proc_service_h)
 utils.o: utils.c $(server_h)
Index: gdbserver/remote-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/remote-utils.c,v
retrieving revision 1.22
diff -u -p -r1.22 remote-utils.c
--- gdbserver/remote-utils.c	16 Oct 2004 17:42:00 -0000	1.22
+++ gdbserver/remote-utils.c	6 Dec 2004 21:58:56 -0000
@@ -721,6 +721,60 @@ decode_M_packet (char *from, CORE_ADDR *
   convert_ascii_to_int (&from[i++], to, *len_ptr);
 }
 
+int
+decode_qGetTLSAddr_args (char *buf, unsigned long *thread_id_ptr,
+                         unsigned long *offset_ptr, CORE_ADDR *lm_ptr)
+{
+  int i = 0;
+  char ch;
+
+  *thread_id_ptr = 0;
+  *offset_ptr = 0;
+  *lm_ptr = 0;
+
+  while ((ch = buf[i++]) && ch != ',')
+    {
+      *thread_id_ptr = *thread_id_ptr << 4;
+      *thread_id_ptr |= fromhex (ch) & 0x0f;
+    }
+
+  if (ch == 0)
+    return 0;
+
+  while ((ch = buf[i++]) && ch != ',')
+    {
+      *offset_ptr = *offset_ptr << 4;
+      *offset_ptr |= fromhex (ch) & 0x0f;
+    }
+
+  if (ch == 0)
+    return 0;
+
+  while ((ch = buf[i++]))
+    {
+      *lm_ptr = *lm_ptr << 4;
+      *lm_ptr |= fromhex (ch) & 0x0f;
+    }
+
+  if (ch == 0)
+    return 1;
+  else
+    return 0;
+}
+
+char *
+encode_qGetTLSAddr_result (char *buf, CORE_ADDR addr)
+{
+  int shft = sizeof (CORE_ADDR) * 8 - 4;
+  while (shft >= 0)
+    {
+      *buf++ = tohex ((addr >> shft) & 0x0f);
+      shft -= 4;
+    }
+  *buf = 0;
+  return buf;
+}
+
 /* Ask GDB for the address of NAME, and return it in ADDRP if found.
    Returns 1 if the symbol is found, 0 if it is not, -1 on error.  */
 
Index: gdbserver/server.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.c,v
retrieving revision 1.22
diff -u -p -r1.22 server.c
--- gdbserver/server.c	5 Mar 2004 03:44:27 -0000	1.22
+++ gdbserver/server.c	6 Dec 2004 21:58:56 -0000
@@ -142,6 +142,37 @@ handle_query (char *own_buf)
       return;
     }
 
+#ifdef USE_THREAD_DB
+  if (strncmp ("qGetTLSAddr:", own_buf, 12) == 0)
+    {
+      unsigned long thread_id, offset;
+      CORE_ADDR link_map_addr, tls_addr;
+      int status;
+
+      status = decode_qGetTLSAddr_args (own_buf + 12, &thread_id, &offset,
+                                        &link_map_addr);
+      if (!status)
+	{
+	  /* Malformed qGetTLSAddr packet.  */
+	  write_enn (own_buf);
+	  return;
+	}
+
+      status = get_thread_local_addr (thread_id, offset, link_map_addr,
+                                      &tls_addr);
+
+      if (!status)
+	{
+	  /* Unable to obtain thread local address.  */
+	  write_enn (own_buf);
+	  return;
+	}
+
+      encode_qGetTLSAddr_result (own_buf, tls_addr);
+      return;
+    }
+#endif
+
   /* Otherwise we didn't know what packet it was.  Say we didn't
      understand it.  */
   own_buf[0] = 0;
Index: gdbserver/server.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.h,v
retrieving revision 1.15
diff -u -p -r1.15 server.h
--- gdbserver/server.h	12 Mar 2004 20:51:21 -0000	1.15
+++ gdbserver/server.h	6 Dec 2004 21:58:56 -0000
@@ -147,6 +147,10 @@ void decode_m_packet (char *from, CORE_A
 void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
 		      unsigned int *len_ptr, char *to);
 
+int decode_qGetTLSAddr_args (char *buf, unsigned long *thread_id_ptr,
+                             unsigned long *offset_ptr, CORE_ADDR *lm_ptr);
+char * encode_qGetTLSAddr_result (char *buf, CORE_ADDR addr);
+
 int unhexify (char *bin, const char *hex, int count);
 int hexify (char *hex, const char *bin, int count);
 
@@ -178,4 +182,8 @@ void init_registers (void);
 		 ? (registers_length () + 32) \
 		 : 2000)
 
+/* Functions from thread-db.c.  */
+
+int get_thread_local_addr (unsigned long thread_id, unsigned long offset,
+                           CORE_ADDR link_map_addr, CORE_ADDR *tls_addr_ptr);
 #endif /* SERVER_H */
Index: gdbserver/thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/thread-db.c,v
retrieving revision 1.2
diff -u -p -r1.2 thread-db.c
--- gdbserver/thread-db.c	16 Oct 2004 17:42:00 -0000	1.2
+++ gdbserver/thread-db.c	6 Dec 2004 21:58:56 -0000
@@ -366,3 +366,27 @@ thread_db_init ()
 
   return 0;
 }
+
+int
+get_thread_local_addr (unsigned long thread_id, unsigned long offset,
+                       CORE_ADDR link_map_addr, CORE_ADDR *tls_addr_ptr)
+{
+  td_thrhandle_t thread_handle;
+  td_err_e status;
+  void *addr;
+
+  status = td_ta_map_id2thr (thread_agent, (thread_t) thread_id,
+                             &thread_handle);
+
+  if (status != TD_OK)
+    return 0;
+
+  status = td_thr_tls_get_addr (&thread_handle, (void *) (long) link_map_addr,
+                                (size_t) offset, &addr);
+  *tls_addr_ptr = (CORE_ADDR) (long) addr;
+
+  if (status != TD_OK)
+    return 0;
+  else
+    return 1;
+}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] gdbserver: Add support for qGetTLSAddr packet
  2004-12-06 22:37 [RFA] gdbserver: Add support for qGetTLSAddr packet Kevin Buettner
@ 2004-12-06 23:48 ` Andreas Schwab
  2005-02-25 15:52 ` Daniel Jacobowitz
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2004-12-06 23:48 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

Kevin Buettner <kevinb@redhat.com> writes:

> Index: gdbserver/Makefile.in
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbserver/Makefile.in,v
> retrieving revision 1.27
> diff -u -p -r1.27 Makefile.in
> --- gdbserver/Makefile.in	16 Oct 2004 16:18:54 -0000	1.27
> +++ gdbserver/Makefile.in	6 Dec 2004 21:58:56 -0000
> @@ -246,6 +246,8 @@ proc-service.o: proc-service.c $(server_
>  regcache.o: regcache.c $(server_h) $(regdef_h)
>  remote-utils.o: remote-utils.c terminal.h $(server_h)
>  server.o: server.c $(server_h)
> +	$(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< @USE_THREAD_DB@

IMHO it is preferable to assign any substitution to a variable and use
that in any reference.  That makes it easier to override it for debugging
or whatever.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] gdbserver: Add support for qGetTLSAddr packet
  2004-12-06 22:37 [RFA] gdbserver: Add support for qGetTLSAddr packet Kevin Buettner
  2004-12-06 23:48 ` Andreas Schwab
@ 2005-02-25 15:52 ` Daniel Jacobowitz
  2005-02-25 21:19   ` Kevin Buettner
  1 sibling, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2005-02-25 15:52 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

On Mon, Dec 06, 2004 at 03:20:02PM -0700, Kevin Buettner wrote:
> The patch below adds qGetTLSAddr packet support to gdbserver.
> 
> I wrote this to demonstrate / test the support that I've added on the
> GDB side.  I suspect some configury tweaking may be needed to test for
> the existence of td_thr_tls_get_addr() in libthread_db.c.  (If it
> doesn't exist, then get_thread_local_addr() should be ifdef'd to return
> a 0 status.)
> 
> If it's otherwise okay, I'm willing to make the necessary configury
> changes.  If it's not okay for some other reason, I'd like to address
> that first...

This should go through the target vector, instead of adding #ifdefs.
Then linux-low.c can handle whether thread-db is present or not.

Is this patch still current, or did the protocol evolve since the last
posting?

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] gdbserver: Add support for qGetTLSAddr packet
  2005-02-25 15:52 ` Daniel Jacobowitz
@ 2005-02-25 21:19   ` Kevin Buettner
  2005-05-01 23:25     ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Buettner @ 2005-02-25 21:19 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

On Thu, 24 Feb 2005 15:53:24 -0500
Daniel Jacobowitz <drow@false.org> wrote:

> On Mon, Dec 06, 2004 at 03:20:02PM -0700, Kevin Buettner wrote:
> > The patch below adds qGetTLSAddr packet support to gdbserver.
> > 
> > I wrote this to demonstrate / test the support that I've added on the
> > GDB side.  I suspect some configury tweaking may be needed to test for
> > the existence of td_thr_tls_get_addr() in libthread_db.c.  (If it
> > doesn't exist, then get_thread_local_addr() should be ifdef'd to return
> > a 0 status.)
> > 
> > If it's otherwise okay, I'm willing to make the necessary configury
> > changes.  If it's not okay for some other reason, I'd like to address
> > that first...
> 
> This should go through the target vector, instead of adding #ifdefs.
> Then linux-low.c can handle whether thread-db is present or not.
> 
> Is this patch still current, or did the protocol evolve since the last
> posting?

The protocol did change, but the patch is still current.  (The protocol
change simply removed the extra load module related parameters that Linux
didn't use anyway.)

Kevin


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] gdbserver: Add support for qGetTLSAddr packet
  2005-02-25 21:19   ` Kevin Buettner
@ 2005-05-01 23:25     ` Daniel Jacobowitz
  2005-05-05 20:05       ` Kevin Buettner
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2005-05-01 23:25 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

On Fri, Feb 25, 2005 at 09:34:29AM -0700, Kevin Buettner wrote:
> On Thu, 24 Feb 2005 15:53:24 -0500
> Daniel Jacobowitz <drow@false.org> wrote:
> 
> > On Mon, Dec 06, 2004 at 03:20:02PM -0700, Kevin Buettner wrote:
> > > The patch below adds qGetTLSAddr packet support to gdbserver.
> > > 
> > > I wrote this to demonstrate / test the support that I've added on the
> > > GDB side.  I suspect some configury tweaking may be needed to test for
> > > the existence of td_thr_tls_get_addr() in libthread_db.c.  (If it
> > > doesn't exist, then get_thread_local_addr() should be ifdef'd to return
> > > a 0 status.)
> > > 
> > > If it's otherwise okay, I'm willing to make the necessary configury
> > > changes.  If it's not okay for some other reason, I'd like to address
> > > that first...
> > 
> > This should go through the target vector, instead of adding #ifdefs.
> > Then linux-low.c can handle whether thread-db is present or not.
> > 
> > Is this patch still current, or did the protocol evolve since the last
> > posting?
> 
> The protocol did change, but the patch is still current.  (The protocol
> change simply removed the extra load module related parameters that Linux
> didn't use anyway.)

Hi Kevin,

Rereading my response, I'm not sure if this was clear: the patch is not
OK without a change to use gdbserver's target vector.  If you won't
have time to do this, let me know, and I'll try to find a chance to do
it myself.

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] gdbserver: Add support for qGetTLSAddr packet
  2005-05-01 23:25     ` Daniel Jacobowitz
@ 2005-05-05 20:05       ` Kevin Buettner
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Buettner @ 2005-05-05 20:05 UTC (permalink / raw)
  To: gdb-patches

On Sun, 1 May 2005 19:25:50 -0400
Daniel Jacobowitz <drow@false.org> wrote:

> On Fri, Feb 25, 2005 at 09:34:29AM -0700, Kevin Buettner wrote:
> > On Thu, 24 Feb 2005 15:53:24 -0500
> > Daniel Jacobowitz <drow@false.org> wrote:
> > 
> > > On Mon, Dec 06, 2004 at 03:20:02PM -0700, Kevin Buettner wrote:
> > > > The patch below adds qGetTLSAddr packet support to gdbserver.
> > > > 
> > > > I wrote this to demonstrate / test the support that I've added on the
> > > > GDB side.  I suspect some configury tweaking may be needed to test for
> > > > the existence of td_thr_tls_get_addr() in libthread_db.c.  (If it
> > > > doesn't exist, then get_thread_local_addr() should be ifdef'd to return
> > > > a 0 status.)
> > > > 
> > > > If it's otherwise okay, I'm willing to make the necessary configury
> > > > changes.  If it's not okay for some other reason, I'd like to address
> > > > that first...
> > > 
> > > This should go through the target vector, instead of adding #ifdefs.
> > > Then linux-low.c can handle whether thread-db is present or not.
> > > 
> > > Is this patch still current, or did the protocol evolve since the last
> > > posting?
> > 
> > The protocol did change, but the patch is still current.  (The protocol
> > change simply removed the extra load module related parameters that Linux
> > didn't use anyway.)
> 
> Hi Kevin,
> 
> Rereading my response, I'm not sure if this was clear: the patch is not
> OK without a change to use gdbserver's target vector.  If you won't
> have time to do this, let me know, and I'll try to find a chance to do
> it myself.

I don't have time for it at the moment, so if you have time for it, great.

Kevin


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-05-05 20:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-06 22:37 [RFA] gdbserver: Add support for qGetTLSAddr packet Kevin Buettner
2004-12-06 23:48 ` Andreas Schwab
2005-02-25 15:52 ` Daniel Jacobowitz
2005-02-25 21:19   ` Kevin Buettner
2005-05-01 23:25     ` Daniel Jacobowitz
2005-05-05 20:05       ` Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox