From: Stan Shebs <stan@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] $thread convenience variable
Date: Mon, 14 Jun 2010 01:31:00 -0000 [thread overview]
Message-ID: <4C158675.9090001@codesourcery.com> (raw)
[-- 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
next reply other threads:[~2010-06-14 1:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-14 1:31 Stan Shebs [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C158675.9090001@codesourcery.com \
--to=stan@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox