From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 110955 invoked by alias); 6 Jan 2016 19:14:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 110941 invoked by uid 89); 6 Jan 2016 19:14:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=GLOBAL, Expect, assigns, Variables X-HELO: usplmg20.ericsson.net Received: from usplmg20.ericsson.net (HELO usplmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 06 Jan 2016 19:14:04 +0000 Received: from EUSAAHC001.ericsson.se (Unknown_Domain [147.117.188.75]) by usplmg20.ericsson.net (Symantec Mail Security) with SMTP id 5E.DD.06940.BA56D865; Wed, 6 Jan 2016 20:06:19 +0100 (CET) Received: from [142.133.110.144] (147.117.188.8) by smtp-am.internal.ericsson.com (147.117.188.77) with Microsoft SMTP Server id 14.3.248.2; Wed, 6 Jan 2016 14:14:02 -0500 Subject: Re: [PATCH v3 7/7] Add $_gthread convenience variable To: Pedro Alves , References: <1452085418-18300-1-git-send-email-palves@redhat.com> <1452085418-18300-8-git-send-email-palves@redhat.com> From: Simon Marchi Message-ID: <568D677A.1090601@ericsson.com> Date: Wed, 06 Jan 2016 19:14:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <1452085418-18300-8-git-send-email-palves@redhat.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg00102.txt.bz2 On 16-01-06 08:03 AM, Pedro Alves wrote: > 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-06 Pedro Alves > > * NEWS: Mention $_gthread. > * gdbthread.h (struct thread_info) : 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-06 Pedro Alves > > * 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-06 Pedro Alves > > * gdb.texinfo (Threads): Document the $_gthread convenience > variable. > (Convenience Vars): Likewise. > --- > gdb/NEWS | 5 ++- > gdb/doc/gdb.texinfo | 9 +++-- > gdb/gdbthread.h | 3 +- > gdb/testsuite/gdb.base/default.exp | 1 + > gdb/testsuite/gdb.multi/tids.exp | 3 +- > gdb/testsuite/gdb.threads/thread-specific.exp | 5 +++ > gdb/thread.c | 49 +++++++++++++++++++++++---- > 7 files changed, 64 insertions(+), 11 deletions(-) > > diff --git a/gdb/NEWS b/gdb/NEWS > index 32e7bd3..e4791cd 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -22,7 +22,7 @@ > > GDB now maintains a second thread ID per thread, referred to as the > global thread ID, which is the new equivalent of thread numbers in > - previous releases. > + previous releases. See also $_gthread below. > > For backwards compatibility, MI's thread IDs always refer to global > IDs. > @@ -37,6 +37,9 @@ > * You can use "info threads -gid" to display the global thread ID of > all threads. > > +* The new convenience variable $_gthread holds the global number of > + the current thread. > + > * The new convenience variable $_inferior holds the number of the > current inferior. > > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index 8ce3b01..f1e5aab 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -2937,8 +2937,10 @@ thread. In other words, @value{GDBN} assigns a thread number to the > program's ``main thread'' even if the program is not multi-threaded. > > @vindex $_thread@r{, convenience variable} > -The debugger convenience variable @samp{$_thread} contains the > -per-inferior thread number of the current thread. You may find this > +@vindex $_gthread@r{, convenience variable} > +The debugger convenience variables @samp{$_thread} and > +@samp{$_gthread} contain, respectively, the per-inferior thread number > +and the global thread number of the current thread. You may find this > useful in writing breakpoint conditional expressions, command scripts, > and so forth. @xref{Convenience Vars,, Convenience Variables}, for > general information on convenience variables. > @@ -10459,6 +10461,9 @@ Programs, ,Debugging Multiple Inferiors and Programs}. > @item $_thread > The thread number of the current thread. @xref{thread numbers}. > > +@item $_gthread > +The global number of the current thread. @xref{global thread numbers}. > + > @end table > > @node Convenience Funs > diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h > index b8d5ac2..f021c65 100644 > --- a/gdb/gdbthread.h > +++ b/gdb/gdbthread.h > @@ -217,7 +217,8 @@ struct thread_info > thread has its own unique global ID. */ > > /* The thread's global GDB thread number. This is exposed to MI, > - Python/Scheme and visible with "info threads -gid". */ > + Python/Scheme, visible with "info threads -gid", and is also what > + the $_gthread convenience variable is bound to. */ > int global_num; > > /* The per-inferior thread number. This is unique in the inferior > diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp > index fec2cde..10739ca 100644 > --- a/gdb/testsuite/gdb.base/default.exp > +++ b/gdb/testsuite/gdb.base/default.exp > @@ -587,6 +587,7 @@ set show_conv_list \ > {$_sdata = void} \ > {$_siginfo = void} \ > {$_thread = 0} \ > + {$_gthread = 0} \ > {$_inferior = 1} \ > {$_exception = } \ > {$_probe_argc = } \ > diff --git a/gdb/testsuite/gdb.multi/tids.exp b/gdb/testsuite/gdb.multi/tids.exp > index badb1f1..cc5f487 100644 > --- a/gdb/testsuite/gdb.multi/tids.exp > +++ b/gdb/testsuite/gdb.multi/tids.exp > @@ -158,8 +158,9 @@ with_test_prefix "two inferiors" { > " 2\.1 +2 +.*" \ > " 2\.2 +3 +.* thread_function1 .* at .*$srcfile:.*"] > > - # Confirm the convenience variable show the expected number. > + # Confirm the convenience variables show the expected numbers. > gdb_test "p \$_thread == 2" " = 1" > + gdb_test "p \$_gthread == 4" " = 1" > > # Without an explicit inferior component, GDB defaults to the > # current inferior. Make sure we don't refer to a thread by > diff --git a/gdb/testsuite/gdb.threads/thread-specific.exp b/gdb/testsuite/gdb.threads/thread-specific.exp > index 2b75b60..8f61f88 100644 > --- a/gdb/testsuite/gdb.threads/thread-specific.exp > +++ b/gdb/testsuite/gdb.threads/thread-specific.exp > @@ -66,7 +66,10 @@ clean_restart ${binfile} > gdb_test_no_output "set print sevenbit-strings" > gdb_test_no_output "set width 0" > > +# As this test only runs a single inferior, $_thread and $_gthread > +# should match throughout. > gdb_test {print $_thread} ".* = 0" "thread var when not running" > +gdb_test {print $_gthread} ".* = 0" "gthread var when not running" > > runto_main > > @@ -82,6 +85,7 @@ if {[llength $threads] == 0} { > } > > gdb_test {print $_thread} ".* = [lindex $threads 0]" "thread var in main" > +gdb_test {print $_gthread} ".* = [lindex $threads 0]" "gthread var in main" > > gdb_test_multiple "break $line thread [lindex $threads 0]" \ > "breakpoint $line main thread" { > @@ -120,6 +124,7 @@ if { $this_breakpoint != -1 } { > > if { $this_thread != -1 } { > gdb_test {print $_thread} ".* = $this_thread" "thread var at break" > + gdb_test {print $_gthread} ".* = $this_thread" "gthread var at break" > } else { > untested "thread var at break" > } > diff --git a/gdb/thread.c b/gdb/thread.c > index 24eb83e..43441ee 100644 > --- a/gdb/thread.c > +++ b/gdb/thread.c > @@ -2061,18 +2061,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'. */ > @@ -2082,7 +2109,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 > }; > @@ -2140,6 +2176,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", >hread_funcs, NULL); > > observer_attach_thread_ptid_changed (restore_current_thread_ptid_changed); > } > LGTM.