* Proposal (#2): qGetTLSAddr remote protocol packet
@ 2004-11-18 21:45 Kevin Buettner
2004-11-19 10:34 ` Eli Zaretskii
0 siblings, 1 reply; 2+ messages in thread
From: Kevin Buettner @ 2004-11-18 21:45 UTC (permalink / raw)
To: gdb
[-- Attachment #1: Type: text/plain, Size: 1894 bytes --]
Below is a revised proposal for a new remote protocol packet for
fetching a thread local storage address. It is written it in a form
(sans markup) that is compatible with the rest of the remote protocol
documentation.
This proposal incorporates feedback from Andrew Cagney and Jim Blandy.
I have also attached patches to gdb and gdbserver which demonstrate an
implementation of this proposal. I'm not asking for approval on the
paches at this time. I'll repost the patches separately, and suitably
modified, to gdb-patches once we get the protocol specification nailed
down.
Further comments / suggestions?
-------------------
qGetTLSAddr:thread-id,offset,load-module-param-1,...,load-module-param-N
-- get thread local storage address
Fetch the address associated with thread local storage specified
by thread-id, offset, and load-module-param-1 thru load-module-param-N.
thread-id is the (big endian, hex encoded) thread id associated with the
thread for which to fetch the TLS address.
offset is the (big endian, hex encoded) offset associated with the
thread local variable. (This offset is obtained from the debug
information associated with the variable.)
load-module-param-1 thru load-module-param-N are (big endian, hex
encoded) data which represent an OS/ABI specific encoding of the load
module. For example, a GNU/Linux system will pass (as
load-module-param-1) the link map address of the shared object
associated with the thread local storage under consideration. Other
operating environments may require different data, so the precise
meaning of these parameters will vary.
Reply:
XX...
Hex encoded (big endian) bytes representing the address of the thread
local storage requested.
Enn (where nn are hex digits)
An error occurred.
"" (empty)
An empty reply indicates that qGetTLSAddr is not supported by the stub.
[-- Attachment #2: 2004-11-18-gdb-qGetTLSAddr.patch --]
[-- Type: text/plain, Size: 8020 bytes --]
* gdbarch.sh (remote_qGetTLSAddr_load_module_params): New method.
* gdbarch.c, gdbarch.h: Regenerate.
* solib-svr4.c, solit-svr4.h
(svr4_nptl_remote_qGetTLSAddr_load_module_params): New function.
* i386-linux-tdep.c (i386_linux_init_abi): Set
remote_qGetTLSAddr_load_module_params method.
* 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.350
diff -u -p -r1.350 gdbarch.sh
--- gdbarch.sh 31 Oct 2004 21:21:41 -0000 1.350
+++ gdbarch.sh 18 Nov 2004 20:51:26 -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: i386-linux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-linux-tdep.c,v
retrieving revision 1.43
diff -u -p -r1.43 i386-linux-tdep.c
--- i386-linux-tdep.c 9 Nov 2004 14:28:42 -0000 1.43
+++ i386-linux-tdep.c 18 Nov 2004 20:51:26 -0000
@@ -437,6 +437,9 @@ i386_linux_init_abi (struct gdbarch_info
set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
dwarf2_frame_set_signal_frame_p (gdbarch, i386_linux_dwarf_signal_frame_p);
+
+ set_gdbarch_remote_qGetTLSAddr_load_module_params
+ (gdbarch, svr4_nptl_remote_qGetTLSAddr_load_module_params);
}
/* Provide a prototype to silence -Wmissing-prototypes. */
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 18 Nov 2004 20:51:26 -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: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.44
diff -u -p -r1.44 solib-svr4.c
--- solib-svr4.c 9 Jun 2004 20:03:33 -0000 1.44
+++ solib-svr4.c 18 Nov 2004 20:51:26 -0000
@@ -1443,6 +1443,27 @@ svr4_lp64_fetch_link_map_offsets (void)
return lmp;
}
\f
+int
+svr4_nptl_remote_qGetTLSAddr_load_module_params (ULONGEST **args_ptr,
+ int *argcnt_ptr,
+ struct objfile *objfile)
+{
+ CORE_ADDR lm;
+
+ lm = svr4_fetch_objfile_link_map (objfile);
+
+ if (!lm)
+ return 0;
+ else
+ {
+ static ULONGEST args[1];
+ args[0] = lm;
+ *args_ptr = args;
+ *argcnt_ptr = 1;
+ return 1;
+ }
+}
+\f
static struct target_so_ops svr4_so_ops;
Index: solib-svr4.h
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.h,v
retrieving revision 1.8
diff -u -p -r1.8 solib-svr4.h
--- solib-svr4.h 12 Mar 2004 22:01:39 -0000 1.8
+++ solib-svr4.h 18 Nov 2004 20:51:26 -0000
@@ -92,4 +92,8 @@ extern struct link_map_offsets *(*legacy
extern struct link_map_offsets *svr4_ilp32_fetch_link_map_offsets (void);
extern struct link_map_offsets *svr4_lp64_fetch_link_map_offsets (void);
+/* Return OS/ABI specific parameters needed for qGetTLSAddr packet. */
+extern int svr4_nptl_remote_qGetTLSAddr_load_module_params
+ (ULONGEST **args_ptr, int *argcnt_ptr, struct objfile *objfile);
+
#endif /* solib-svr4.h */
[-- Attachment #3: 2004-11-18-gdbserver-qGetTLSAddr.patch --]
[-- Type: text/plain, Size: 5857 bytes --]
* 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: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/Makefile.in,v
retrieving revision 1.27
diff -u -p -r1.27 Makefile.in
--- Makefile.in 16 Oct 2004 16:18:54 -0000 1.27
+++ Makefile.in 18 Nov 2004 20:45:49 -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: 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
--- remote-utils.c 16 Oct 2004 17:42:00 -0000 1.22
+++ remote-utils.c 18 Nov 2004 20:45:49 -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: server.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.c,v
retrieving revision 1.22
diff -u -p -r1.22 server.c
--- server.c 5 Mar 2004 03:44:27 -0000 1.22
+++ server.c 18 Nov 2004 20:45:49 -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: server.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.h,v
retrieving revision 1.15
diff -u -p -r1.15 server.h
--- server.h 12 Mar 2004 20:51:21 -0000 1.15
+++ server.h 18 Nov 2004 20:45:49 -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: 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
--- thread-db.c 16 Oct 2004 17:42:00 -0000 1.2
+++ thread-db.c 18 Nov 2004 20:45:49 -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] 2+ messages in thread
* Re: Proposal (#2): qGetTLSAddr remote protocol packet
2004-11-18 21:45 Proposal (#2): qGetTLSAddr remote protocol packet Kevin Buettner
@ 2004-11-19 10:34 ` Eli Zaretskii
0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2004-11-19 10:34 UTC (permalink / raw)
To: Kevin Buettner; +Cc: gdb
> Date: Thu, 18 Nov 2004 14:22:14 -0700
> From: Kevin Buettner <kevinb@redhat.com>
>
> Below is a revised proposal for a new remote protocol packet for
> fetching a thread local storage address. It is written it in a form
> (sans markup) that is compatible with the rest of the remote protocol
> documentation.
The documentation part is okay with me (sans the missing markup).
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-11-19 7:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-18 21:45 Proposal (#2): qGetTLSAddr remote protocol packet Kevin Buettner
2004-11-19 10:34 ` Eli Zaretskii
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox