* thread.c (thread_id_make_value): Make a value representing the
authorStan Shebs <shebs@codesourcery.com>
Fri, 18 Jun 2010 17:44:40 +0000 (17:44 +0000)
committerStan Shebs <shebs@codesourcery.com>
Fri, 18 Jun 2010 17:44:40 +0000 (17:44 +0000)
current thread.
(_initialize_thread): Create $_thread.

* gdb.texinfo (Debugging Programs with Multiple Threads): Describe
$_thread.

* gdb.threads/thread-specific.exp: Add tests of $_thread.

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.threads/thread-specific.exp
gdb/thread.c

index 15c7c8513eca6f73d38725d68d6b2477d4e3f295..fd4355322f34d4dc58cbe06ecf37970226e88072 100644 (file)
@@ -1,3 +1,9 @@
+2010-06-18  Stan Shebs  <stan@codesourcery.com>
+
+       * thread.c (thread_id_make_value): Make a value representing the
+       current thread.
+       (_initialize_thread): Create $_thread.
+
 2010-06-17  Joel Brobecker  <brobecker@adacore.com>
 
        * dwarf2read.c (psymtabs_addrmap_cleanup): Add empty line after
index 60ae888805429207c17a2bd9bdca38634273b0fc..e85334604db95dd10fdf16ea72f3b74b7d5514d8 100644 (file)
@@ -1,3 +1,8 @@
+2010-06-18  Stan Shebs  <stan@codesourcery.com>
+
+       * gdb.texinfo (Debugging Programs with Multiple Threads): Describe
+       $_thread.
+
 2010-06-18  Hui Zhu  <teawater@gmail.com>
 
        * gdb.texinfo: (Process Record and Replay): Add documentation
index 03752b6788b94f09dc0f315cbdea12012a95c660..8c1969678bbb6621f3f31e9136f6e33598dc4a37 100644 (file)
@@ -2788,6 +2788,13 @@ As with the @samp{[New @dots{}]} message, the form of the text after
 @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
+@xref{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 d789a4138b5b478494fb4062ab11b07e04e72af6..3b61976f054056bb771ffb0556fce80190ef1a40 100644 (file)
@@ -1,3 +1,7 @@
+2010-06-18  Stan Shebs  <stan@codesourcery.com>
+
+       * gdb.threads/thread-specific.exp: Add tests of $_thread.
+
 2010-06-18  Ulrich Weigand  <Ulrich.Weigand@de.ibm.com>
 
        * gdb.base/gdb11531.exp: Respect gdb,no_hardware_watchpoints flag.
index 623d805bd8672d9e2b64c08ff3e7896a6915370a..662eec36640c9a4d491c57e229ba3e1cec1c487b 100644 (file)
@@ -75,6 +75,8 @@ gdb_load ${binfile}
 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"]
@@ -88,6 +90,8 @@ if {[llength $threads] == 0} {
   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 $" {
@@ -104,9 +108,19 @@ gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
        -re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
            fail "continue to thread-specific breakpoint (wrong breakpoint)"
        }
-       -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
+       -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
index c10d23c9f2114d93478a60683009e7a603b6392b..2fdc7f9b326fc47eba28b44b7d6a4796885329ae 100644 (file)
@@ -1262,6 +1262,18 @@ update_thread_list (void)
   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;
 
@@ -1295,4 +1307,6 @@ Show printing of thread events (such as thread start and exit)."), NULL,
          NULL,
          show_print_thread_events,
          &setprintlist, &showprintlist);
+
+  create_internalvar_type_lazy ("_thread", thread_id_make_value);
 }
This page took 0.065523 seconds and 4 git commands to generate.