This is the mail archive of the gdb-patches@sources.redhat.com 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]

[RFC] Generic support for qGetTLSAddr packet


The patch below implements support for the qGetTLSAddr packet.  See:

    http://sources.redhat.com/ml/gdb/2004-11/msg00189.html

This patch also adds a new gdbarch method for fetching the OS / ABI
specific load module parameters.

Still to come are three patches.  They do the following:

    - Add documentation of remote_qGetTLSAddr_load_module_params to
      gdbint.texinfo.
    - Instantiate remote_qGetTLSAddr_load_module_params for GNU/Linux
      running on an i386.
    - Provide an implementation of the qGetTLSAddr packet for
      gdbserver.

The documentation patch for the qGetTLSAddr packet has already been posted.
It may be found at:

    http://sources.redhat.com/ml/gdb-patches/2004-12/msg00168.html

Comments?

	* gdbarch.sh (remote_qGetTLSAddr_load_module_params): New method.
	* gdbarch.c, gdbarch.h: Regenerate.
	* remote.c (remote_protocol_qGetTLSAddr): New static global variable.
	(set_remote_protocol_qGetTLSAddr_packet_cmd)
	(show_remote_protocol_qGetTLSAddr_packet_cmd)
	(remote_get_thread_local_address): New functions.
	(init_all_packet_configs): Initialize remote_protocol_qGetTLSAddr
	variable.
	(init_remote_ops): Initialize ``to_get_thread_local_address'' in
	target vector.
	(show_remote_cmd): Call show_remote_protocol_qGetTLS_Addr_packet_cmd().
	(_initialize_remote):  Add support for the "set remote
	get-thread-local-storage-address-packet' and "show remote
	get-thread-local-address-packet" commands.

Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.352
diff -u -p -r1.352 gdbarch.sh
--- gdbarch.sh	3 Dec 2004 23:59:52 -0000	1.352
+++ gdbarch.sh	6 Dec 2004 20:59:23 -0000
@@ -567,6 +567,9 @@ v:=:CORE_ADDR:decr_pc_after_break:::0:::
 v:=:CORE_ADDR:deprecated_function_start_offset:::0:::0
 
 m::void:remote_translate_xfer_address:struct regcache *regcache, CORE_ADDR gdb_addr, int gdb_len, CORE_ADDR *rem_addr, int *rem_len:regcache, gdb_addr, gdb_len, rem_addr, rem_len::generic_remote_translate_xfer_address::0
+
+# Fill in the additional parameters required to remotely fetch a TLS address
+F:=:int:remote_qGetTLSAddr_load_module_params:ULONGEST **args_ptr, int *argcnt_ptr, struct objfile *objfile:args_ptr, argcnt_ptr, objfile
 #
 v:=:CORE_ADDR:frame_args_skip:::0:::0
 M::CORE_ADDR:unwind_pc:struct frame_info *next_frame:next_frame
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.153
diff -u -p -r1.153 remote.c
--- remote.c	11 Nov 2004 18:59:39 -0000	1.153
+++ remote.c	6 Dec 2004 20:59:24 -0000
@@ -961,6 +961,23 @@ show_remote_protocol_qPart_auxv_packet_c
   show_packet_config_cmd (&remote_protocol_qPart_auxv);
 }
 
+/* Should we try the 'qGetTLSAddr' (Get Thread Local Storage Address) request? */
+static struct packet_config remote_protocol_qGetTLSAddr;
+
+static void
+set_remote_protocol_qGetTLSAddr_packet_cmd (char *args, int from_tty,
+				  struct cmd_list_element *c)
+{
+  update_packet_config (&remote_protocol_qGetTLSAddr);
+}
+
+static void
+show_remote_protocol_qGetTLSAddr_packet_cmd (char *args, int from_tty,
+					 struct cmd_list_element *c)
+{
+  show_packet_config_cmd (&remote_protocol_qGetTLSAddr);
+}
+
 static struct packet_config remote_protocol_p;
 
 static void
@@ -2067,6 +2084,7 @@ init_all_packet_configs (void)
      downloading. */
   update_packet_config (&remote_protocol_binary_download);
   update_packet_config (&remote_protocol_qPart_auxv);
+  update_packet_config (&remote_protocol_qGetTLSAddr);
 }
 
 /* Symbol look-up. */
@@ -5233,6 +5251,52 @@ remote_pid_to_str (ptid_t ptid)
   return buf;
 }
 
+/* Get the address of the thread local variable in OBJFILE which is
+   stored at OFFSET within the thread local storage for thread PTID.  */
+
+static CORE_ADDR
+remote_get_thread_local_address (ptid_t ptid, struct objfile *objfile,
+				 CORE_ADDR offset)
+{
+  if (remote_protocol_qGetTLSAddr.support != PACKET_DISABLE
+      && gdbarch_remote_qGetTLSAddr_load_module_params_p (current_gdbarch))
+    {
+      struct remote_state *rs = get_remote_state ();
+      char *buf = alloca (rs->remote_packet_size);
+      char *p = buf;
+      int status, argcnt;
+      ULONGEST *extra_args;
+
+      strcpy (p, "qGetTLSAddr:");
+      p += strlen (p);
+      p += hexnumstr (p, PIDGET (ptid));
+      *p++ = ',';
+      p += hexnumstr (p, offset);
+      status = gdbarch_remote_qGetTLSAddr_load_module_params
+                 (current_gdbarch, &extra_args, &argcnt, objfile);
+      if (status)
+	{
+	  int i;
+	  for (i = 0; i < argcnt; i++)
+	    {
+	      *p++ = ',';
+	      p += hexnumstr (p, extra_args[i]);
+	    }
+
+	  putpkt (buf);
+	  getpkt (buf, rs->remote_packet_size, 0);
+	  if (packet_ok (buf, &remote_protocol_qGetTLSAddr) == PACKET_OK)
+	    {
+	      ULONGEST result;
+
+	      unpack_varlen_hex (buf, &result);
+	      return result;
+	    }
+	}
+    }
+  error ("Cannot find thread-local values on this target.");
+}
+
 static void
 init_remote_ops (void)
 {
@@ -5272,6 +5336,7 @@ Specify the serial device it is connecte
   remote_ops.to_stop = remote_stop;
   remote_ops.to_xfer_partial = remote_xfer_partial;
   remote_ops.to_rcmd = remote_rcmd;
+  remote_ops.to_get_thread_local_address = remote_get_thread_local_address;
   remote_ops.to_stratum = process_stratum;
   remote_ops.to_has_all_memory = 1;
   remote_ops.to_has_memory = 1;
@@ -5444,6 +5509,7 @@ show_remote_cmd (char *args, int from_tt
   show_remote_protocol_vcont_packet_cmd (args, from_tty, NULL);
   show_remote_protocol_binary_download_cmd (args, from_tty, NULL);
   show_remote_protocol_qPart_auxv_packet_cmd (args, from_tty, NULL);
+  show_remote_protocol_qGetTLSAddr_packet_cmd (args, from_tty, NULL);
 }
 
 static void
@@ -5685,6 +5751,13 @@ in a memory packet.\n",
 			 &remote_set_cmdlist, &remote_show_cmdlist,
 			 0);
 
+  add_packet_config_cmd (&remote_protocol_qGetTLSAddr,
+			 "qGetTLSAddr", "get-thread-local-storage-address",
+			 set_remote_protocol_qGetTLSAddr_packet_cmd,
+			 show_remote_protocol_qGetTLSAddr_packet_cmd,
+			 &remote_set_cmdlist, &remote_show_cmdlist,
+			 0);
+
   /* Keep the old ``set remote Z-packet ...'' working. */
   add_setshow_auto_boolean_cmd ("Z-packet", class_obscure,
 				&remote_Z_packet_detect, "\


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