Add thread_handle_to_thread_info support for remote targets

This patch adds support to remote targets for converting a thread
handle to a thread_info struct pointer.

A thread handle is fetched via a "handle" attribute which has been
added to the qXfer:threads:read query packet.  An implementation is
provided in gdbserver for targets using the Linux kernel.

gdb/gdbserver/ChangeLog:

	* linux-low.h (struct lwp_info): Add new field, thread_handle.
	(thread_db_thread_handle): Declare.
	* linux-low.c (linux_target_ops): Initialize thread_handle.
	* server.c (handle_qxfer_threads_worker): Add support for
	"handle" attribute.
	* target.h (struct target_ops): Add new function pointer,
	thread_handle.
	(target_thread_handle): Define.
	* thread-db.c (find_one_thread, attach_thread): Set thread_handle
	field in lwp.
	(thread_db_thread_handle): New function.

gdb/ChangeLog:

	* remote.c (vector): Include.
	(struct private_thread_info): Add field, thread_handle.
	(free_private_thread_info): Deallocate storage associated with
	thread handle.
	(get_private_info_thread): Initialize `thread_handle' field.
	(struct thread_item): Add field, thread_handle.
	(clear_threads_listing_context): Deallocate storage associated
	with thread handle.
	(start_thread): Add support for "handle" attribute.
	(thread_attributes): Add "handle".
	(remote_get_threads_with_qthreadinfo): Initialize thread_handle
	field.
	(remote_update_thread_list): Update thread_handle.
	(remote_thread_handle_to_thread_info): New function.
	(init_remote_ops): Initialize to_thread_handle_to_thread_info.
This commit is contained in:
Kevin Buettner 2017-04-04 16:17:05 -07:00
parent 8629910955
commit f6327dcbf0
8 changed files with 153 additions and 0 deletions

View file

@ -1648,6 +1648,9 @@ handle_qxfer_threads_worker (struct inferior_list_entry *inf, void *arg)
int core = target_core_of_thread (ptid);
char core_s[21];
const char *name = target_thread_name (ptid);
int handle_len;
gdb_byte *handle;
bool handle_status = target_thread_handle (ptid, &handle, &handle_len);
write_ptid (ptid_s, ptid);
@ -1662,6 +1665,13 @@ handle_qxfer_threads_worker (struct inferior_list_entry *inf, void *arg)
if (name != NULL)
buffer_xml_printf (buffer, " name=\"%s\"", name);
if (handle_status)
{
char *handle_s = (char *) alloca (handle_len * 2 + 1);
bin2hex (handle, handle_s, handle_len);
buffer_xml_printf (buffer, " handle=\"%s\"", handle_s);
}
buffer_xml_printf (buffer, "/>\n");
}