Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: [RFA] gdbserver: Add support for qGetTLSAddr packet
Date: Mon, 06 Dec 2004 22:37:00 -0000	[thread overview]
Message-ID: <20041206152002.551f8d46.kevinb@redhat.com> (raw)

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


             reply	other threads:[~2004-12-06 22:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-06 22:37 Kevin Buettner [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041206152002.551f8d46.kevinb@redhat.com \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox