aboutsummaryrefslogtreecommitdiff
path: root/gdb/thread.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-01-13 10:56:10 +0000
committerPedro Alves <palves@redhat.com>2016-01-13 11:03:19 +0000
commit663f6d42f47265d2deaa86c8a976e658fb13f820 (patch)
treebd245ce035bd243e40c05056a39ee0d28e8bc3c5 /gdb/thread.c
parentc84f6bbfe50ff13928360d3cc349d7c553867ce6 (diff)
downloadfsf-binutils-gdb-663f6d42f47265d2deaa86c8a976e658fb13f820.zip
fsf-binutils-gdb-663f6d42f47265d2deaa86c8a976e658fb13f820.tar.gz
fsf-binutils-gdb-663f6d42f47265d2deaa86c8a976e658fb13f820.tar.bz2
Add $_gthread convenience variable
This commit adds a new $_gthread convenience variable, that is like $_thread, but holds the current thread's global thread id. gdb/ChangeLog: 2016-01-13 Pedro Alves <palves@redhat.com> * NEWS: Mention $_gthread. * gdbthread.h (struct thread_info) <global_num>: Mention $_gthread. * thread.c (thread_num_make_value_helper): New function. (thread_id_make_value): Delete. (thread_id_per_inf_num_make_value, global_thread_id_make_value): New. (thread_funcs): Adjust. (gthread_funcs): New. (_initialize_thread): Register $_gthread variable. gdb/testsuite/ChangeLog: 2016-01-13 Pedro Alves <palves@redhat.com> * gdb.base/default.exp: Expect $_gthread as well. * gdb.multi/tids.exp: Test $_gthread. * gdb.threads/thread-specific.exp: Test $_gthread. gdb/doc/ChangeLog: 2016-01-13 Pedro Alves <palves@redhat.com> * gdb.texinfo (Threads): Document the $_gthread convenience variable. (Convenience Vars): Likewise.
Diffstat (limited to 'gdb/thread.c')
-rw-r--r--gdb/thread.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/gdb/thread.c b/gdb/thread.c
index 8ec6a38..cdd2a2f 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -2083,18 +2083,45 @@ update_thread_list (void)
update_threads_executing ();
}
+/* Return a new value for the selected thread's id. Return a value of
+ 0 if no thread is selected. If GLOBAL is true, return the thread's
+ global number. Otherwise return the per-inferior number. */
+
+static struct value *
+thread_num_make_value_helper (struct gdbarch *gdbarch, int global)
+{
+ struct thread_info *tp = find_thread_ptid (inferior_ptid);
+ int int_val;
+
+ if (tp == NULL)
+ int_val = 0;
+ else if (global)
+ int_val = tp->global_num;
+ else
+ int_val = tp->per_inf_num;
+
+ return value_from_longest (builtin_type (gdbarch)->builtin_int, int_val);
+}
+
/* Return a new value for the selected thread's per-inferior thread
number. Return a value of 0 if no thread is selected, or no
threads exist. */
static struct value *
-thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
- void *ignore)
+thread_id_per_inf_num_make_value (struct gdbarch *gdbarch, struct internalvar *var,
+ void *ignore)
{
- struct thread_info *tp = find_thread_ptid (inferior_ptid);
+ return thread_num_make_value_helper (gdbarch, 0);
+}
+
+/* Return a new value for the selected thread's global id. Return a
+ value of 0 if no thread is selected, or no threads exist. */
- return value_from_longest (builtin_type (gdbarch)->builtin_int,
- (tp ? tp->per_inf_num : 0));
+static struct value *
+global_thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
+ void *ignore)
+{
+ return thread_num_make_value_helper (gdbarch, 1);
}
/* Commands with a prefix of `thread'. */
@@ -2104,7 +2131,16 @@ struct cmd_list_element *thread_cmd_list = NULL;
static const struct internalvar_funcs thread_funcs =
{
- thread_id_make_value,
+ thread_id_per_inf_num_make_value,
+ NULL,
+ NULL
+};
+
+/* Implementation of `gthread' variable. */
+
+static const struct internalvar_funcs gthread_funcs =
+{
+ global_thread_id_make_value,
NULL,
NULL
};
@@ -2162,6 +2198,7 @@ Show printing of thread events (such as thread start and exit)."), NULL,
&setprintlist, &showprintlist);
create_internalvar_type_lazy ("_thread", &thread_funcs, NULL);
+ create_internalvar_type_lazy ("_gthread", &gthread_funcs, NULL);
observer_attach_thread_ptid_changed (restore_current_thread_ptid_changed);
}