From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27353 invoked by alias); 14 Jun 2010 01:31:55 -0000 Received: (qmail 27344 invoked by uid 22791); 14 Jun 2010 01:31:54 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Jun 2010 01:31:48 +0000 Received: (qmail 32345 invoked from network); 14 Jun 2010 01:31:46 -0000 Received: from unknown (HELO macbook-2.local) (stan@127.0.0.2) by mail.codesourcery.com with ESMTPA; 14 Jun 2010 01:31:46 -0000 Message-ID: <4C158675.9090001@codesourcery.com> Date: Mon, 14 Jun 2010 01:31:00 -0000 From: Stan Shebs User-Agent: Thunderbird 2.0.0.24 (Macintosh/20100228) MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [PATCH] $thread convenience variable Content-Type: multipart/mixed; boundary="------------070104070801070209010005" 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 X-SW-Source: 2010-06/txt/msg00299.txt.bz2 This is a multi-part message in MIME format. --------------070104070801070209010005 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 759 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 * 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. --------------070104070801070209010005 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="dolthread-patch-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="dolthread-patch-1" Content-length: 4172 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 --------------070104070801070209010005--