[PATCH] Another annotation for threads

Nick Roberts
2008-05-21T02:54:32Z

This is a patch for another annotation, this time for thread changes. It
follows an earlier patch (not committed) for notifying thread changes in MI
using observers. In that patch thread changes were notified in two places:
normal_stop in infrun.c and do_captured_thread_select in thread.c. Here
normal_stop is used but the second call has been moved to thread_command so
that temporary thread changes in commands like "info thread", "-var-update" etc
aren't reported.

In the doc patch, I've used @r{, annotation} with findex but I don't know what
all this does as annotate.texinfo doesn't appear to have a function index.

If this patch is OK, I will submit a similar one for MI using an observer.

--
Nick http://www.inet.net.nz/~nickrob

2008-05-21 Nick Roberts <nickrob@snap.net.nz>

* annotate.c (annotate_thread_changed): New function.
* thread.c (thread_command) : Use it.
* infrun.c (normal_stop): Use it.

2008-05-21 Nick Roberts <nickrob@snap.net.nz>

* annotate.texinfo (Multi-threaded Apps): Add entry for thread-changed
annotation.

2008-05-21 Nick Roberts <nickrob@snap.net.nz>

* gdb.base/annota1.exp (thread_switch): Test for thread-changed
annotation.

--- annotate.c.~1.16.~ 2008-05-17 10:27:23.000000000 +1200
+++ annotate.c 2008-05-21 10:25:51.000000000 +1200
@@ -243,6 +243,15 @@ annotate_new_thread (void)
}

void
+annotate_thread_changed (void)
+{
+ if (annotation_level > 1)
+ {
+ printf_unfiltered (("\n\032\032thread-changed\n"));
+ }
+}
+
+void
annotate_field_begin (struct type *type)
{
if (annotation_level == 2)

--- thread.c.~1.70.~ 2008-05-17 20:02:16.000000000 +1200
+++ thread.c 2008-05-21 10:55:29.000000000 +1200
@@ -738,6 +738,7 @@ thread_command (char *tidstr, int from_t
return;
}

+ annotate_thread_changed ();
gdb_thread_select (uiout, tidstr, NULL);
}

--- infrun.c.~1.277.~ 2008-05-08 16:32:23.000000000 +1200
+++ infrun.c 2008-05-21 10:26:59.000000000 +1200
@@ -3605,6 +3605,7 @@ normal_stop (void)
target_terminal_ours_for_output ();
printf_filtered (_("[Switching to %s]\n"),
target_pid_to_str (inferior_ptid));
+ annotate_thread_changed ();
previous_inferior_ptid = inferior_ptid;
}

--- annotate.texinfo.~1.9.~ 2008-05-21 13:53:53.000000000 +1200
+++ annotate.texinfo 2008-05-21 14:14:18.000000000 +1200
@@ -825,17 +825,24 @@ depend on the language).
@chapter Multi-threaded Applications
@cindex annotations for multi-threaded apps

-@findex new-thread@r{, annotation}
-The following annotation reports that the application being debugged is
-multi-threaded.
+The following annotations report thread related changes of state.

-@smallexample
-^Z^Znew-thread
-@end smallexample
+@table @code
+@findex new-thread@r{, annotation}
+@item ^Z^Znew-thread

This annotation is issued once for each thread that is created apart from
the main thread, which is not reported.

+@findex thread-changed@r{, annotation}
+@item ^Z^Zthread-changed
+
+The selected thread has changed. This may occur at the request of the
+user with the @code{thread} command, or as a result of execution,
+e.g., another thread hits a breakpoint.
+
+@end table
+
@raisesections
@include fdl.texi
@lowersections

--- annota1.exp.~1.30.~ 2008-05-20 18:48:14.000000000 +1200
+++ annota1.exp 2008-05-21 13:51:11.000000000 +1200
@@ -527,7 +527,18 @@ proc thread_test {} {
}
}

+proc thread_switch {} {
+ send_gdb "thread 1\n"
+ gdb_expect {
+ -re ".*\032\032thread-changed" {
+ pass "thread switch"
+ }
+ timeout { fail "thread switch (timeout)" }
+ }
+}
+
thread_test
+thread_switch

# restore the original prompt for the rest of the testsuite