* [PATCH] $thread convenience variable
@ 2010-06-14 1:31 Stan Shebs
2010-06-14 3:00 ` Eli Zaretskii
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Stan Shebs @ 2010-06-14 1:31 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 759 bytes --]
This little patch adds a periodically-requested convenience variable
whose value is the current thread. It's handy in scripts and
conditionals, since the GDB-assigned thread id is unpredictable.
Although the original request was for "$thread", it might be better to
make it "$_thread" instead, so as not to interfere with possible use in
existing scripts. But I'll only change it if I get enough votes in
favor. :-)
Stan
2010-06-13 Stan Shebs <stan@codesourcery.com>
* thread.c (thread_id_make_value): Make a value representing the
current thread.
(_initialize_thread): Create $thread.
* gdb.texinfo (Debugging Programs with Multiple Threads): Describe
$thread.
* gdb.threads/thread-specific.exp: Add tests of $thread.
[-- Attachment #2: dolthread-patch-1 --]
[-- Type: text/plain, Size: 4172 bytes --]
Index: thread.c
===================================================================
RCS file: /cvs/src/src/gdb/thread.c,v
retrieving revision 1.120
diff -p -r1.120 thread.c
*** thread.c 17 May 2010 01:15:20 -0000 1.120
--- thread.c 14 Jun 2010 01:20:14 -0000
*************** update_thread_list (void)
*** 1262,1267 ****
--- 1262,1279 ----
target_find_new_threads ();
}
+ /* Return a new value for the selected thread's id. 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)
+ {
+ struct thread_info *tp = find_thread_ptid (inferior_ptid);
+
+ return value_from_longest (builtin_type (gdbarch)->builtin_int,
+ (tp ? tp->num : 0));
+ }
+
/* Commands with a prefix of `thread'. */
struct cmd_list_element *thread_cmd_list = NULL;
*************** Show printing of thread events (such as
*** 1295,1298 ****
--- 1307,1312 ----
NULL,
show_print_thread_events,
&setprintlist, &showprintlist);
+
+ create_internalvar_type_lazy ("thread", thread_id_make_value);
}
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.722
diff -p -r1.722 gdb.texinfo
*** doc/gdb.texinfo 12 Jun 2010 00:05:21 -0000 1.722
--- doc/gdb.texinfo 14 Jun 2010 01:20:14 -0000
*************** As with the @samp{[New @dots{}]} message
*** 2788,2793 ****
--- 2788,2800 ----
@samp{Switching to} depends on your system's conventions for identifying
threads.
+ @vindex $thread@r{, convenience variable}
+ The debugger convenience variable @samp{$thread} contains the number
+ of the current thread. You may find this useful in writing breakpoint
+ conditional expressions, command scripts, and so forth. See
+ @ref{Convenience Vars,, Convenience Variables}, for general
+ information on convenience variables.
+
@kindex thread apply
@cindex apply command to several threads
@item thread apply [@var{threadno}] [@var{all}] @var{command}
Index: testsuite/gdb.threads/thread-specific.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.threads/thread-specific.exp,v
retrieving revision 1.12
diff -p -r1.12 thread-specific.exp
*** testsuite/gdb.threads/thread-specific.exp 2 Jun 2010 21:53:28 -0000 1.12
--- testsuite/gdb.threads/thread-specific.exp 14 Jun 2010 01:20:14 -0000
*************** gdb_load ${binfile}
*** 75,80 ****
--- 75,82 ----
gdb_test_no_output "set print sevenbit-strings"
gdb_test_no_output "set width 0"
+ gdb_test {print $thread} ".* = 0" "thread var when not running"
+
runto_main
gdb_breakpoint [gdb_get_line_number "thread-specific.exp: last thread start"]
*************** if {[llength $threads] == 0} {
*** 88,93 ****
--- 90,97 ----
return 1
}
+ gdb_test {print $thread} ".* = [lindex $threads 0]" "thread var in main"
+
gdb_test_multiple "break $line thread [lindex $threads 0]" \
"breakpoint $line main thread" {
-re "Breakpoint (\[0-9\]*) at.* file .*$srcfile, line.*$gdb_prompt $" {
*************** gdb_test_multiple "continue" "continue t
*** 104,112 ****
-re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
fail "continue to thread-specific breakpoint (wrong breakpoint)"
}
! -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
pass "continue to thread-specific breakpoint"
}
}
return 0
--- 108,126 ----
-re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
fail "continue to thread-specific breakpoint (wrong breakpoint)"
}
! -re "Breakpoint (\[0-9\]*), .* at .*\r\n$gdb_prompt $" {
! set this_breakpoint $expect_out(1,string)
pass "continue to thread-specific breakpoint"
}
}
+ gdb_test_multiple "info breakpoint $this_breakpoint" "info on bp" {
+ -re ".*stop only in thread (\[0-9\]*).*$gdb_prompt $" {
+ set this_thread $expect_out(1,string)
+ pass "found breakpoint for thread number"
+ }
+ }
+
+ gdb_test {print $thread} ".* = $this_thread" "thread var at break"
+
return 0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] $thread convenience variable
2010-06-14 1:31 [PATCH] $thread convenience variable Stan Shebs
@ 2010-06-14 3:00 ` Eli Zaretskii
2010-06-14 9:14 ` Pierre Muller
2010-06-14 18:36 ` Tom Tromey
2 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2010-06-14 3:00 UTC (permalink / raw)
To: Stan Shebs; +Cc: gdb-patches
> Date: Sun, 13 Jun 2010 18:31:33 -0700
> From: Stan Shebs <stan@codesourcery.com>
>
> + See
> + @ref{Convenience Vars,, Convenience Variables},
This should be just @xref.
The patch for the manual is okay, with this change.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] $thread convenience variable
2010-06-14 1:31 [PATCH] $thread convenience variable Stan Shebs
2010-06-14 3:00 ` Eli Zaretskii
@ 2010-06-14 9:14 ` Pierre Muller
2010-06-14 18:36 ` Tom Tromey
2 siblings, 0 replies; 6+ messages in thread
From: Pierre Muller @ 2010-06-14 9:14 UTC (permalink / raw)
To: 'Stan Shebs', gdb-patches
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Stan Shebs
> Envoyé : Monday, June 14, 2010 3:32 AM
> À : gdb-patches@sourceware.org
> Objet : [PATCH] $thread convenience variable
>
> This little patch adds a periodically-requested convenience variable
> whose value is the current thread. It's handy in scripts and
> conditionals, since the GDB-assigned thread id is unpredictable.
>
> Although the original request was for "$thread", it might be better to
> make it "$_thread" instead, so as not to interfere with possible use in
> existing scripts. But I'll only change it if I get enough votes in
> favor. :-)
By analogy with:
_exitcode
_siginfo
and
_tlb
internal variables defined so far,
I would vote in favor of '$_thread'.
The only other internal variables I found
are 'bpnum', 'tpnum' and a whole bunch of 'trace_.*' variables.
Pierre Muller
Pascal language support maintainer for GDB
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] $thread convenience variable
2010-06-14 1:31 [PATCH] $thread convenience variable Stan Shebs
2010-06-14 3:00 ` Eli Zaretskii
2010-06-14 9:14 ` Pierre Muller
@ 2010-06-14 18:36 ` Tom Tromey
2010-06-18 17:46 ` Stan Shebs
2 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2010-06-14 18:36 UTC (permalink / raw)
To: Stan Shebs; +Cc: gdb-patches
>>>>> "Stan" == Stan Shebs <stan@codesourcery.com> writes:
Stan> Although the original request was for "$thread", it might be better to
Stan> make it "$_thread" instead, so as not to interfere with possible use
Stan> in existing scripts. But I'll only change it if I get enough votes in
Stan> favor. :-)
I have a vague memory that the last time this came up we decided that
all new built-in convenience variables would start with "_", or
something like that.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] $thread convenience variable
2010-06-14 18:36 ` Tom Tromey
@ 2010-06-18 17:46 ` Stan Shebs
2010-06-18 17:58 ` Pedro Alves
0 siblings, 1 reply; 6+ messages in thread
From: Stan Shebs @ 2010-06-18 17:46 UTC (permalink / raw)
To: tromey; +Cc: Stan Shebs, gdb-patches
Tom Tromey wrote:
>>>>>> "Stan" == Stan Shebs <stan@codesourcery.com> writes:
>>>>>>
>
> Stan> Although the original request was for "$thread", it might be better to
> Stan> make it "$_thread" instead, so as not to interfere with possible use
> Stan> in existing scripts. But I'll only change it if I get enough votes in
> Stan> favor. :-)
>
> I have a vague memory that the last time this came up we decided that
> all new built-in convenience variables would start with "_", or
> something like that.
>
I vaguely remember that too, we should probably write it down
somewhere. :-) In any case, I committed as $_thread .
Stan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] $thread convenience variable
2010-06-18 17:46 ` Stan Shebs
@ 2010-06-18 17:58 ` Pedro Alves
0 siblings, 0 replies; 6+ messages in thread
From: Pedro Alves @ 2010-06-18 17:58 UTC (permalink / raw)
To: gdb-patches; +Cc: Stan Shebs, tromey
On Friday 18 June 2010 18:46:20, Stan Shebs wrote:
> Tom Tromey wrote:
> >>>>>> "Stan" == Stan Shebs <stan@codesourcery.com> writes:
> >>>>>>
> >
> > Stan> Although the original request was for "$thread", it might be better to
> > Stan> make it "$_thread" instead, so as not to interfere with possible use
> > Stan> in existing scripts. But I'll only change it if I get enough votes in
> > Stan> favor. :-)
> >
> > I have a vague memory that the last time this came up we decided that
> > all new built-in convenience variables would start with "_", or
> > something like that.
> >
> I vaguely remember that too, we should probably write it down
> somewhere. :-) In any case, I committed as $_thread .
I think this warrants a NEWS entry.
(we have also decided to document all new commands and remote
protocol packets in NEWS, so you're owing a couple entries
already. ;-) It would be very nice to have that addressed
before 7.2.)
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-06-18 17:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-14 1:31 [PATCH] $thread convenience variable Stan Shebs
2010-06-14 3:00 ` Eli Zaretskii
2010-06-14 9:14 ` Pierre Muller
2010-06-14 18:36 ` Tom Tromey
2010-06-18 17:46 ` Stan Shebs
2010-06-18 17:58 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).