public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add "thread-exited" annotation
@ 2019-04-26 15:19 Amos Bird
  2019-04-30 15:45 ` Tom Tromey
  0 siblings, 1 reply; 19+ messages in thread
From: Amos Bird @ 2019-04-26 15:19 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 157 bytes --]


This patch adds "thread-exited" annotation so that annotation 
based clients like cgdb could currently handle thread exit.

--
Amos Bird
amosbird@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-thread-exit-annotation.patch --]
[-- Type: text/x-patch, Size: 1461 bytes --]

From 890aa5099b92b5c05bd03b1084926460f6aa0d7a Mon Sep 17 00:00:00 2001
From: Amos Bird <amosbird@gmail.com>
Date: Fri, 26 Apr 2019 23:09:11 +0800
Subject: [PATCH] Add "thread-exit" annotation.

---
 gdb/ChangeLog  |  5 +++++
 gdb/annotate.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0120e7743..849ed30731 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.c (annotate_thread_exited): Add "thread-exited"
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 97cb4c8855..b3a7343a5a 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -241,6 +241,17 @@ annotate_thread_changed (void)
     }
 }
 
+void
+annotate_thread_exited (struct thread_info *t, int silent)
+{
+  if (annotation_level > 1)
+    {
+      printf_filtered(("\n\032\032thread-exited,"
+                       "id=\"%d\",group-id=\"i%d\"\n"),
+                      t->global_num, t->inf->num);
+    }
+}
+
 void
 annotate_field_begin (struct type *type)
 {
@@ -595,4 +606,5 @@ _initialize_annotate (void)
   gdb::observers::breakpoint_created.attach (breakpoint_changed);
   gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
   gdb::observers::breakpoint_modified.attach (breakpoint_changed);
+  gdb::observers::thread_exit.attach (annotate_thread_exited);
 }
-- 
2.21.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-04-26 15:19 [PATCH] Add "thread-exited" annotation Amos Bird
@ 2019-04-30 15:45 ` Tom Tromey
  2019-04-30 17:09   ` Amos Bird
  0 siblings, 1 reply; 19+ messages in thread
From: Tom Tromey @ 2019-04-30 15:45 UTC (permalink / raw)
  To: Amos Bird; +Cc: gdb-patches

>>>>> "Amos" == Amos Bird <amosbird@gmail.com> writes:

Amos> This patch adds "thread-exited" annotation so that annotation based
Amos> clients like cgdb could currently handle thread exit.

I sort of wish that all clients would just use MI, but ...

Amos> +2019-04-26  Amos Bird  <amosbird@gmail.com>
Amos> +
Amos> +	* annotate.c (annotate_thread_exited): Add "thread-exited"
Amos> +	annotation.

The patch itself is fine (just some nits), but a change like this
requires a documentation update (and probably NEWS as well) and a test
case.

 
Amos> +void
Amos> +annotate_thread_exited (struct thread_info *t, int silent)
Amos> +{

New functions should have an intro comment.  Also, this function should
be "static".

Tom

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-04-30 15:45 ` Tom Tromey
@ 2019-04-30 17:09   ` Amos Bird
  2019-05-16 13:14     ` Gary Benson
  0 siblings, 1 reply; 19+ messages in thread
From: Amos Bird @ 2019-04-30 17:09 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 867 bytes --]

Patch updated.

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Amos" == Amos Bird <amosbird@gmail.com> writes:
>
> Amos> This patch adds "thread-exited" annotation so that 
> annotation based
> Amos> clients like cgdb could currently handle thread exit.
>
> I sort of wish that all clients would just use MI, but ...
>
> Amos> +2019-04-26  Amos Bird  <amosbird@gmail.com>
> Amos> +
> Amos> +	* annotate.c (annotate_thread_exited): Add 
> "thread-exited"
> Amos> +	annotation.
>
> The patch itself is fine (just some nits), but a change like 
> this
> requires a documentation update (and probably NEWS as well) and 
> a test
> case.
>
>
> Amos> +void
> Amos> +annotate_thread_exited (struct thread_info *t, int 
> silent)
> Amos> +{
>
> New functions should have an intro comment.  Also, this function 
> should
> be "static".
>
> Tom


--
Amos Bird
amosbird@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-thread-exit-annotation.patch --]
[-- Type: text/x-patch, Size: 4063 bytes --]

From b910b30abba42992bec4a011cc13c6eb1f20a43a Mon Sep 17 00:00:00 2001
From: Amos Bird <amosbird@gmail.com>
Date: Fri, 26 Apr 2019 23:09:11 +0800
Subject: [PATCH] Add "thread-exit" annotation.

---
 gdb/ChangeLog                      |  5 +++++
 gdb/NEWS                           |  2 ++
 gdb/annotate.c                     | 14 ++++++++++++++
 gdb/doc/ChangeLog                  |  5 +++++
 gdb/doc/annotate.texinfo           |  5 +++++
 gdb/testsuite/ChangeLog            |  5 +++++
 gdb/testsuite/gdb.base/annota1.exp |  9 +++++++++
 7 files changed, 45 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0120e7743..849ed30731 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.c (annotate_thread_exited): Add "thread-exited"
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/NEWS b/gdb/NEWS
index 5309a8f923..df5f836bac 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,8 @@
 
 *** Changes since GDB 8.3
 
+* 'thread-exited' event is now available in the old annotations interface
+
 * New built-in convenience variables $_gdb_major and $_gdb_minor
   provide the GDB version.  They are handy for conditionally using
   features available only in or since specific GDB versions, in
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 97cb4c8855..af804ddd1f 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -241,6 +241,19 @@ annotate_thread_changed (void)
     }
 }
 
+/* Emit notification on thread exit.  */
+
+static void
+annotate_thread_exited (struct thread_info *t, int silent)
+{
+  if (annotation_level > 1)
+    {
+      printf_filtered(("\n\032\032thread-exited,"
+                       "id=\"%d\",group-id=\"i%d\"\n"),
+                      t->global_num, t->inf->num);
+    }
+}
+
 void
 annotate_field_begin (struct type *type)
 {
@@ -595,4 +608,5 @@ _initialize_annotate (void)
   gdb::observers::breakpoint_created.attach (breakpoint_changed);
   gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
   gdb::observers::breakpoint_modified.attach (breakpoint_changed);
+  gdb::observers::thread_exit.attach (annotate_thread_exited);
 }
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ba152329d7..79b837aac6 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
+	annotation.
+
 2019-04-22  Pedro Alves  <palves@redhat.com>
 
 	* gdb.texinfo (Reverse Execution): Mention and xref process record
diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
index b85b759f9a..38978f3ccc 100644
--- a/gdb/doc/annotate.texinfo
+++ b/gdb/doc/annotate.texinfo
@@ -836,6 +836,11 @@ 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.
 
+@findex thread-exited@r{, annotation}
+@item ^Z^Zthread-exited
+
+This annotation is issued once for each thread that is exited.
+
 @end table
 
 @node GNU Free Documentation License
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9b0725a033..169b5b8dce 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* gdb.base/annota1.exp (thread_switch): Test for thread-exited
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
index 5237bc9715..032cd2ecde 100644
--- a/gdb/testsuite/gdb.base/annota1.exp
+++ b/gdb/testsuite/gdb.base/annota1.exp
@@ -492,8 +492,17 @@ proc thread_switch {} {
     }
 }
 
+proc thread_exit {} {
+    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {
+	-re ".*\032\032thread-exited.*" {
+	    pass "thread exit"
+	}
+    }
+}
+
 thread_test
 thread_switch
+thread_exit
 
 # restore the original prompt for the rest of the testsuite
 
-- 
2.21.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-04-30 17:09   ` Amos Bird
@ 2019-05-16 13:14     ` Gary Benson
  2019-05-16 14:10       ` Amos Bird
  0 siblings, 1 reply; 19+ messages in thread
From: Gary Benson @ 2019-05-16 13:14 UTC (permalink / raw)
  To: gdb-patches; +Cc: Amos Bird, Tom Tromey

Hi Amos,

I've only the two nits detailed below, other than those the patch
seems fine.

Cheers,
Gary

Amos Bird wrote:
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 5309a8f923..df5f836bac 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,8 @@
>  
>  *** Changes since GDB 8.3
>  
> +* 'thread-exited' event is now available in the old annotations interface

I'd lose the "old" here.

> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
> index 9b0725a033..169b5b8dce 100644
> --- a/gdb/testsuite/ChangeLog
> +++ b/gdb/testsuite/ChangeLog
> @@ -1,3 +1,8 @@
> +2019-04-26  Amos Bird  <amosbird@gmail.com>
> +
> +	* gdb.base/annota1.exp (thread_switch): Test for thread-exited
> +	annotation.
> +

I'd say "Add test..." here.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-16 13:14     ` Gary Benson
@ 2019-05-16 14:10       ` Amos Bird
  2019-05-16 14:35         ` Eli Zaretskii
  0 siblings, 1 reply; 19+ messages in thread
From: Amos Bird @ 2019-05-16 14:10 UTC (permalink / raw)
  To: Gary Benson; +Cc: gdb-patches, Tom Tromey

[-- Attachment #1: Type: text/plain, Size: 887 bytes --]


Thanks! Patch updated.

Gary Benson <gbenson@redhat.com> writes:

> Hi Amos,
>
> I've only the two nits detailed below, other than those the 
> patch
> seems fine.
>
> Cheers,
> Gary
>
> Amos Bird wrote:
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index 5309a8f923..df5f836bac 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -3,6 +3,8 @@
>>
>>  *** Changes since GDB 8.3
>>
>> +* 'thread-exited' event is now available in the old 
>> annotations interface
>
> I'd lose the "old" here.
>
>> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
>> index 9b0725a033..169b5b8dce 100644
>> --- a/gdb/testsuite/ChangeLog
>> +++ b/gdb/testsuite/ChangeLog
>> @@ -1,3 +1,8 @@
>> +2019-04-26  Amos Bird  <amosbird@gmail.com>
>> +
>> +	* gdb.base/annota1.exp (thread_switch): Test for 
>> thread-exited
>> +	annotation.
>> +
>
> I'd say "Add test..." here.


--
Amos Bird
amosbird@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-thread-exit-annotation.patch --]
[-- Type: text/x-patch, Size: 4063 bytes --]

From d014f0b921fba63264bd57a7d791cbf202f70c8a Mon Sep 17 00:00:00 2001
From: Amos Bird <amosbird@gmail.com>
Date: Thu, 16 May 2019 22:08:57 +0800
Subject: [PATCH] Add "thread-exit" annotation.

---
 gdb/ChangeLog                      |  5 +++++
 gdb/NEWS                           |  2 ++
 gdb/annotate.c                     | 14 ++++++++++++++
 gdb/doc/ChangeLog                  |  5 +++++
 gdb/doc/annotate.texinfo           |  5 +++++
 gdb/testsuite/ChangeLog            |  5 +++++
 gdb/testsuite/gdb.base/annota1.exp |  9 +++++++++
 7 files changed, 45 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0120e7743..849ed30731 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.c (annotate_thread_exited): Add "thread-exited"
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/NEWS b/gdb/NEWS
index 5309a8f923..f1d21c62be 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,8 @@
 
 *** Changes since GDB 8.3
 
+* 'thread-exited' event is now available in the annotations interface
+
 * New built-in convenience variables $_gdb_major and $_gdb_minor
   provide the GDB version.  They are handy for conditionally using
   features available only in or since specific GDB versions, in
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 97cb4c8855..af804ddd1f 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -241,6 +241,19 @@ annotate_thread_changed (void)
     }
 }
 
+/* Emit notification on thread exit.  */
+
+static void
+annotate_thread_exited (struct thread_info *t, int silent)
+{
+  if (annotation_level > 1)
+    {
+      printf_filtered(("\n\032\032thread-exited,"
+                       "id=\"%d\",group-id=\"i%d\"\n"),
+                      t->global_num, t->inf->num);
+    }
+}
+
 void
 annotate_field_begin (struct type *type)
 {
@@ -595,4 +608,5 @@ _initialize_annotate (void)
   gdb::observers::breakpoint_created.attach (breakpoint_changed);
   gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
   gdb::observers::breakpoint_modified.attach (breakpoint_changed);
+  gdb::observers::thread_exit.attach (annotate_thread_exited);
 }
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ba152329d7..79b837aac6 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
+	annotation.
+
 2019-04-22  Pedro Alves  <palves@redhat.com>
 
 	* gdb.texinfo (Reverse Execution): Mention and xref process record
diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
index b85b759f9a..38978f3ccc 100644
--- a/gdb/doc/annotate.texinfo
+++ b/gdb/doc/annotate.texinfo
@@ -836,6 +836,11 @@ 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.
 
+@findex thread-exited@r{, annotation}
+@item ^Z^Zthread-exited
+
+This annotation is issued once for each thread that is exited.
+
 @end table
 
 @node GNU Free Documentation License
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9b0725a033..d7a9b5611d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* gdb.base/annota1.exp (thread_switch): Add test for
+	thread-exited annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
index 5237bc9715..032cd2ecde 100644
--- a/gdb/testsuite/gdb.base/annota1.exp
+++ b/gdb/testsuite/gdb.base/annota1.exp
@@ -492,8 +492,17 @@ proc thread_switch {} {
     }
 }
 
+proc thread_exit {} {
+    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {
+	-re ".*\032\032thread-exited.*" {
+	    pass "thread exit"
+	}
+    }
+}
+
 thread_test
 thread_switch
+thread_exit
 
 # restore the original prompt for the rest of the testsuite
 
-- 
2.21.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-16 14:10       ` Amos Bird
@ 2019-05-16 14:35         ` Eli Zaretskii
  2019-05-16 14:45           ` Amos Bird
  0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2019-05-16 14:35 UTC (permalink / raw)
  To: Amos Bird; +Cc: gbenson, gdb-patches, tom

> From: Amos Bird <amosbird@gmail.com>
> Cc: gdb-patches@sourceware.org, Tom Tromey <tom@tromey.com>
> Date: Thu, 16 May 2019 22:10:14 +0800
> 
> +* 'thread-exited' event is now available in the annotations interface

A period at the end of the sentence is missing.

> +This annotation is issued once for each thread that is exited.
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
"each thread that exits"

The documentation parts are OK with these 2 nits fixed.

Thanks.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-16 14:35         ` Eli Zaretskii
@ 2019-05-16 14:45           ` Amos Bird
  2019-05-17  9:59             ` Gary Benson
  2019-05-17 13:08             ` Simon Marchi
  0 siblings, 2 replies; 19+ messages in thread
From: Amos Bird @ 2019-05-16 14:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gbenson, gdb-patches, tom

[-- Attachment #1: Type: text/plain, Size: 602 bytes --]


Thanks. Updated.
Eli Zaretskii <eliz@gnu.org> writes:

>> From: Amos Bird <amosbird@gmail.com>
>> Cc: gdb-patches@sourceware.org, Tom Tromey <tom@tromey.com>
>> Date: Thu, 16 May 2019 22:10:14 +0800
>>
>> +* 'thread-exited' event is now available in the annotations 
>> interface
>
> A period at the end of the sentence is missing.
>
>> +This annotation is issued once for each thread that is exited.
>                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
> "each thread that exits"
>
> The documentation parts are OK with these 2 nits fixed.
>
> Thanks.


--
Amos Bird
amosbird@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-thread-exit-annotation.patch --]
[-- Type: text/x-patch, Size: 4060 bytes --]

From b6dc912764a0e61e274b9354ca225af4a235a3dd Mon Sep 17 00:00:00 2001
From: Amos Bird <amosbird@gmail.com>
Date: Thu, 16 May 2019 22:44:40 +0800
Subject: [PATCH] Add "thread-exit" annotation.

---
 gdb/ChangeLog                      |  5 +++++
 gdb/NEWS                           |  2 ++
 gdb/annotate.c                     | 14 ++++++++++++++
 gdb/doc/ChangeLog                  |  5 +++++
 gdb/doc/annotate.texinfo           |  5 +++++
 gdb/testsuite/ChangeLog            |  5 +++++
 gdb/testsuite/gdb.base/annota1.exp |  9 +++++++++
 7 files changed, 45 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0120e7743..849ed30731 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.c (annotate_thread_exited): Add "thread-exited"
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/NEWS b/gdb/NEWS
index 5309a8f923..735d915ec6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,8 @@
 
 *** Changes since GDB 8.3
 
+* 'thread-exited' event is now available in the annotations interface.
+
 * New built-in convenience variables $_gdb_major and $_gdb_minor
   provide the GDB version.  They are handy for conditionally using
   features available only in or since specific GDB versions, in
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 97cb4c8855..af804ddd1f 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -241,6 +241,19 @@ annotate_thread_changed (void)
     }
 }
 
+/* Emit notification on thread exit.  */
+
+static void
+annotate_thread_exited (struct thread_info *t, int silent)
+{
+  if (annotation_level > 1)
+    {
+      printf_filtered(("\n\032\032thread-exited,"
+                       "id=\"%d\",group-id=\"i%d\"\n"),
+                      t->global_num, t->inf->num);
+    }
+}
+
 void
 annotate_field_begin (struct type *type)
 {
@@ -595,4 +608,5 @@ _initialize_annotate (void)
   gdb::observers::breakpoint_created.attach (breakpoint_changed);
   gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
   gdb::observers::breakpoint_modified.attach (breakpoint_changed);
+  gdb::observers::thread_exit.attach (annotate_thread_exited);
 }
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ba152329d7..79b837aac6 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
+	annotation.
+
 2019-04-22  Pedro Alves  <palves@redhat.com>
 
 	* gdb.texinfo (Reverse Execution): Mention and xref process record
diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
index b85b759f9a..fb7cbf7b77 100644
--- a/gdb/doc/annotate.texinfo
+++ b/gdb/doc/annotate.texinfo
@@ -836,6 +836,11 @@ 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.
 
+@findex thread-exited@r{, annotation}
+@item ^Z^Zthread-exited
+
+This annotation is issued once for each thread that exits.
+
 @end table
 
 @node GNU Free Documentation License
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9b0725a033..d7a9b5611d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* gdb.base/annota1.exp (thread_switch): Add test for
+	thread-exited annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
index 5237bc9715..032cd2ecde 100644
--- a/gdb/testsuite/gdb.base/annota1.exp
+++ b/gdb/testsuite/gdb.base/annota1.exp
@@ -492,8 +492,17 @@ proc thread_switch {} {
     }
 }
 
+proc thread_exit {} {
+    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {
+	-re ".*\032\032thread-exited.*" {
+	    pass "thread exit"
+	}
+    }
+}
+
 thread_test
 thread_switch
+thread_exit
 
 # restore the original prompt for the rest of the testsuite
 
-- 
2.21.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-16 14:45           ` Amos Bird
@ 2019-05-17  9:59             ` Gary Benson
  2019-05-17 10:55               ` Amos Bird
  2019-05-17 13:08             ` Simon Marchi
  1 sibling, 1 reply; 19+ messages in thread
From: Gary Benson @ 2019-05-17  9:59 UTC (permalink / raw)
  To: Amos Bird; +Cc: Eli Zaretskii, gdb-patches, tom

Amos Bird wrote:
> Thanks. Updated.

Cool.  I'm happy for this to be committed now, but I'm not a
maintainer so I can't approve it.

Also, Amos, do you have copyright assignment in place?

Thanks,
Gary

> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >>From: Amos Bird <amosbird@gmail.com>
> >>Cc: gdb-patches@sourceware.org, Tom Tromey <tom@tromey.com>
> >>Date: Thu, 16 May 2019 22:10:14 +0800
> >>
> >>+* 'thread-exited' event is now available in the annotations
> >>interface
> >
> >A period at the end of the sentence is missing.
> >
> >>+This annotation is issued once for each thread that is exited.
> >                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
> >"each thread that exits"
> >
> >The documentation parts are OK with these 2 nits fixed.
> >
> >Thanks.
> 
> 
> --
> Amos Bird
> amosbird@gmail.com

> From b6dc912764a0e61e274b9354ca225af4a235a3dd Mon Sep 17 00:00:00 2001
> From: Amos Bird <amosbird@gmail.com>
> Date: Thu, 16 May 2019 22:44:40 +0800
> Subject: [PATCH] Add "thread-exit" annotation.
> 
> ---
>  gdb/ChangeLog                      |  5 +++++
>  gdb/NEWS                           |  2 ++
>  gdb/annotate.c                     | 14 ++++++++++++++
>  gdb/doc/ChangeLog                  |  5 +++++
>  gdb/doc/annotate.texinfo           |  5 +++++
>  gdb/testsuite/ChangeLog            |  5 +++++
>  gdb/testsuite/gdb.base/annota1.exp |  9 +++++++++
>  7 files changed, 45 insertions(+)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index e0120e7743..849ed30731 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2019-04-26  Amos Bird  <amosbird@gmail.com>
> +
> +	* annotate.c (annotate_thread_exited): Add "thread-exited"
> +	annotation.
> +
>  2019-04-25  Keith Seitz  <keiths@redhat.com>
>  
>  	PR c++/24367
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 5309a8f923..735d915ec6 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,8 @@
>  
>  *** Changes since GDB 8.3
>  
> +* 'thread-exited' event is now available in the annotations interface.
> +
>  * New built-in convenience variables $_gdb_major and $_gdb_minor
>    provide the GDB version.  They are handy for conditionally using
>    features available only in or since specific GDB versions, in
> diff --git a/gdb/annotate.c b/gdb/annotate.c
> index 97cb4c8855..af804ddd1f 100644
> --- a/gdb/annotate.c
> +++ b/gdb/annotate.c
> @@ -241,6 +241,19 @@ annotate_thread_changed (void)
>      }
>  }
>  
> +/* Emit notification on thread exit.  */
> +
> +static void
> +annotate_thread_exited (struct thread_info *t, int silent)
> +{
> +  if (annotation_level > 1)
> +    {
> +      printf_filtered(("\n\032\032thread-exited,"
> +                       "id=\"%d\",group-id=\"i%d\"\n"),
> +                      t->global_num, t->inf->num);
> +    }
> +}
> +
>  void
>  annotate_field_begin (struct type *type)
>  {
> @@ -595,4 +608,5 @@ _initialize_annotate (void)
>    gdb::observers::breakpoint_created.attach (breakpoint_changed);
>    gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
>    gdb::observers::breakpoint_modified.attach (breakpoint_changed);
> +  gdb::observers::thread_exit.attach (annotate_thread_exited);
>  }
> diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
> index ba152329d7..79b837aac6 100644
> --- a/gdb/doc/ChangeLog
> +++ b/gdb/doc/ChangeLog
> @@ -1,3 +1,8 @@
> +2019-04-26  Amos Bird  <amosbird@gmail.com>
> +
> +	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
> +	annotation.
> +
>  2019-04-22  Pedro Alves  <palves@redhat.com>
>  
>  	* gdb.texinfo (Reverse Execution): Mention and xref process record
> diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
> index b85b759f9a..fb7cbf7b77 100644
> --- a/gdb/doc/annotate.texinfo
> +++ b/gdb/doc/annotate.texinfo
> @@ -836,6 +836,11 @@ 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.
>  
> +@findex thread-exited@r{, annotation}
> +@item ^Z^Zthread-exited
> +
> +This annotation is issued once for each thread that exits.
> +
>  @end table
>  
>  @node GNU Free Documentation License
> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
> index 9b0725a033..d7a9b5611d 100644
> --- a/gdb/testsuite/ChangeLog
> +++ b/gdb/testsuite/ChangeLog
> @@ -1,3 +1,8 @@
> +2019-04-26  Amos Bird  <amosbird@gmail.com>
> +
> +	* gdb.base/annota1.exp (thread_switch): Add test for
> +	thread-exited annotation.
> +
>  2019-04-25  Keith Seitz  <keiths@redhat.com>
>  
>  	PR c++/24367
> diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
> index 5237bc9715..032cd2ecde 100644
> --- a/gdb/testsuite/gdb.base/annota1.exp
> +++ b/gdb/testsuite/gdb.base/annota1.exp
> @@ -492,8 +492,17 @@ proc thread_switch {} {
>      }
>  }
>  
> +proc thread_exit {} {
> +    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {
> +	-re ".*\032\032thread-exited.*" {
> +	    pass "thread exit"
> +	}
> +    }
> +}
> +
>  thread_test
>  thread_switch
> +thread_exit
>  
>  # restore the original prompt for the rest of the testsuite
>  
> -- 
> 2.21.0
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-17  9:59             ` Gary Benson
@ 2019-05-17 10:55               ` Amos Bird
  0 siblings, 0 replies; 19+ messages in thread
From: Amos Bird @ 2019-05-17 10:55 UTC (permalink / raw)
  To: Gary Benson; +Cc: Eli Zaretskii, gdb-patches, tom



> Also, Amos, do you have copyright assignment in place?
Yup, it's all set.

Gary Benson <gbenson@redhat.com> writes:

> Amos Bird wrote:
>> Thanks. Updated.
>
> Cool.  I'm happy for this to be committed now, but I'm not a
> maintainer so I can't approve it.
>
> Also, Amos, do you have copyright assignment in place?
>
> Thanks,
> Gary
>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >>From: Amos Bird <amosbird@gmail.com>
>> >>Cc: gdb-patches@sourceware.org, Tom Tromey <tom@tromey.com>
>> >>Date: Thu, 16 May 2019 22:10:14 +0800
>> >>
>> >>+* 'thread-exited' event is now available in the annotations
>> >>interface
>> >
>> >A period at the end of the sentence is missing.
>> >
>> >>+This annotation is issued once for each thread that is 
>> >>exited.
>> >                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
>> >"each thread that exits"
>> >
>> >The documentation parts are OK with these 2 nits fixed.
>> >
>> >Thanks.
>>
>>
>> --
>> Amos Bird
>> amosbird@gmail.com
>
>> From b6dc912764a0e61e274b9354ca225af4a235a3dd Mon Sep 17 
>> 00:00:00 2001
>> From: Amos Bird <amosbird@gmail.com>
>> Date: Thu, 16 May 2019 22:44:40 +0800
>> Subject: [PATCH] Add "thread-exit" annotation.
>>
>> ---
>>  gdb/ChangeLog                      |  5 +++++
>>  gdb/NEWS                           |  2 ++
>>  gdb/annotate.c                     | 14 ++++++++++++++
>>  gdb/doc/ChangeLog                  |  5 +++++
>>  gdb/doc/annotate.texinfo           |  5 +++++
>>  gdb/testsuite/ChangeLog            |  5 +++++
>>  gdb/testsuite/gdb.base/annota1.exp |  9 +++++++++
>>  7 files changed, 45 insertions(+)
>>
>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>> index e0120e7743..849ed30731 100644
>> --- a/gdb/ChangeLog
>> +++ b/gdb/ChangeLog
>> @@ -1,3 +1,8 @@
>> +2019-04-26  Amos Bird  <amosbird@gmail.com>
>> +
>> +	* annotate.c (annotate_thread_exited): Add "thread-exited"
>> +	annotation.
>> +
>>  2019-04-25  Keith Seitz  <keiths@redhat.com>
>>
>>  	PR c++/24367
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index 5309a8f923..735d915ec6 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -3,6 +3,8 @@
>>
>>  *** Changes since GDB 8.3
>>
>> +* 'thread-exited' event is now available in the annotations 
>> interface.
>> +
>>  * New built-in convenience variables $_gdb_major and 
>>  $_gdb_minor
>>    provide the GDB version.  They are handy for conditionally 
>>    using
>>    features available only in or since specific GDB versions, 
>>    in
>> diff --git a/gdb/annotate.c b/gdb/annotate.c
>> index 97cb4c8855..af804ddd1f 100644
>> --- a/gdb/annotate.c
>> +++ b/gdb/annotate.c
>> @@ -241,6 +241,19 @@ annotate_thread_changed (void)
>>      }
>>  }
>>
>> +/* Emit notification on thread exit.  */
>> +
>> +static void
>> +annotate_thread_exited (struct thread_info *t, int silent)
>> +{
>> +  if (annotation_level > 1)
>> +    {
>> +      printf_filtered(("\n\032\032thread-exited,"
>> +                       "id=\"%d\",group-id=\"i%d\"\n"),
>> +                      t->global_num, t->inf->num);
>> +    }
>> +}
>> +
>>  void
>>  annotate_field_begin (struct type *type)
>>  {
>> @@ -595,4 +608,5 @@ _initialize_annotate (void)
>>    gdb::observers::breakpoint_created.attach 
>>    (breakpoint_changed);
>>    gdb::observers::breakpoint_deleted.attach 
>>    (breakpoint_changed);
>>    gdb::observers::breakpoint_modified.attach 
>>    (breakpoint_changed);
>> +  gdb::observers::thread_exit.attach (annotate_thread_exited);
>>  }
>> diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
>> index ba152329d7..79b837aac6 100644
>> --- a/gdb/doc/ChangeLog
>> +++ b/gdb/doc/ChangeLog
>> @@ -1,3 +1,8 @@
>> +2019-04-26  Amos Bird  <amosbird@gmail.com>
>> +
>> +	* annotate.texinfo (Multi-threaded Apps): Add entry for 
>> thread-exited
>> +	annotation.
>> +
>>  2019-04-22  Pedro Alves  <palves@redhat.com>
>>
>>  	* gdb.texinfo (Reverse Execution): Mention and xref 
>>  process record
>> diff --git a/gdb/doc/annotate.texinfo 
>> b/gdb/doc/annotate.texinfo
>> index b85b759f9a..fb7cbf7b77 100644
>> --- a/gdb/doc/annotate.texinfo
>> +++ b/gdb/doc/annotate.texinfo
>> @@ -836,6 +836,11 @@ 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.
>>
>> +@findex thread-exited@r{, annotation}
>> +@item ^Z^Zthread-exited
>> +
>> +This annotation is issued once for each thread that exits.
>> +
>>  @end table
>>
>>  @node GNU Free Documentation License
>> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
>> index 9b0725a033..d7a9b5611d 100644
>> --- a/gdb/testsuite/ChangeLog
>> +++ b/gdb/testsuite/ChangeLog
>> @@ -1,3 +1,8 @@
>> +2019-04-26  Amos Bird  <amosbird@gmail.com>
>> +
>> +	* gdb.base/annota1.exp (thread_switch): Add test for
>> +	thread-exited annotation.
>> +
>>  2019-04-25  Keith Seitz  <keiths@redhat.com>
>>
>>  	PR c++/24367
>> diff --git a/gdb/testsuite/gdb.base/annota1.exp 
>> b/gdb/testsuite/gdb.base/annota1.exp
>> index 5237bc9715..032cd2ecde 100644
>> --- a/gdb/testsuite/gdb.base/annota1.exp
>> +++ b/gdb/testsuite/gdb.base/annota1.exp
>> @@ -492,8 +492,17 @@ proc thread_switch {} {
>>      }
>>  }
>>
>> +proc thread_exit {} {
>> +    gdb_test_multiple "call (void)pthread_exit()" "thread 
>> exit" {
>> +	-re ".*\032\032thread-exited.*" {
>> +	    pass "thread exit"
>> +	}
>> +    }
>> +}
>> +
>>  thread_test
>>  thread_switch
>> +thread_exit
>>
>>  # restore the original prompt for the rest of the testsuite
>>
>> --
>> 2.21.0
>>


--
Amos Bird
amosbird@gmail.com

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-16 14:45           ` Amos Bird
  2019-05-17  9:59             ` Gary Benson
@ 2019-05-17 13:08             ` Simon Marchi
  2019-05-17 13:23               ` Amos Bird
  1 sibling, 1 reply; 19+ messages in thread
From: Simon Marchi @ 2019-05-17 13:08 UTC (permalink / raw)
  To: Amos Bird, Eli Zaretskii; +Cc: gbenson, gdb-patches, tom

Hi Amos,

Some comments related to the format of arguments passed with the annotation:

> +      printf_filtered(("\n\032\032thread-exited,"
> +                       "id=\"%d\",group-id=\"i%d\"\n"),
> +                      t->global_num, t->inf->num);

Do we use this style of MI-like record anywhere else in the annotations interface?

Other annotations that have extra info seem to just pass magic numbers after the
annotation name, such as:

    printf_filtered (("\n\032\032frame-begin %d %s\n"),
		     level, paddress (gdbarch, pc));

I don't mind if we start using MI-like syntax for annotation parameters, but it should
be a conscious decision to do so.  And if we ever add more annotations in the future, it
should follow the same pattern.

> diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
> index b85b759f9a..fb7cbf7b77 100644
> --- a/gdb/doc/annotate.texinfo
> +++ b/gdb/doc/annotate.texinfo
> @@ -836,6 +836,11 @@ 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.
>
> +@findex thread-exited@r{, annotation}
> +@item ^Z^Zthread-exited
> +
> +This annotation is issued once for each thread that exits.
> +
>  @end table

In any case, the documentation should describe the format and meaning of
information passed with the annotation.

> +proc thread_exit {} {
> +    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {
> +	-re ".*\032\032thread-exited.*" {
> +	    pass "thread exit"
> +	}
> +    }
> +}

Please enhance the regex to include the extra information, like (untested):

  -re ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\""

Simon

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-17 13:08             ` Simon Marchi
@ 2019-05-17 13:23               ` Amos Bird
  2019-05-17 14:22                 ` Simon Marchi
  0 siblings, 1 reply; 19+ messages in thread
From: Amos Bird @ 2019-05-17 13:23 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Eli Zaretskii, gbenson, gdb-patches, tom

[-- Attachment #1: Type: text/plain, Size: 2222 bytes --]


Hi Simon,

> I don't mind if we start using MI-like syntax for annotation 
> parameters, but it should
> be a conscious decision to do so.

To be honest I don't use the extra information at all in cgdb, 
only "thread-exited". So
I'm OK to whatever format it ends up to have.

Patch updated, thanks!

Simon Marchi <simark@simark.ca> writes:

> Hi Amos,
>
> Some comments related to the format of arguments passed with the 
> annotation:
>
>> +      printf_filtered(("\n\032\032thread-exited,"
>> +                       "id=\"%d\",group-id=\"i%d\"\n"),
>> +                      t->global_num, t->inf->num);
>
> Do we use this style of MI-like record anywhere else in the 
> annotations interface?
>
> Other annotations that have extra info seem to just pass magic 
> numbers after the
> annotation name, such as:
>
>     printf_filtered (("\n\032\032frame-begin %d %s\n"),
> 		     level, paddress (gdbarch, pc));
>
> I don't mind if we start using MI-like syntax for annotation 
> parameters, but it should
> be a conscious decision to do so.  And if we ever add more 
> annotations in the future, it
> should follow the same pattern.
>
>> diff --git a/gdb/doc/annotate.texinfo 
>> b/gdb/doc/annotate.texinfo
>> index b85b759f9a..fb7cbf7b77 100644
>> --- a/gdb/doc/annotate.texinfo
>> +++ b/gdb/doc/annotate.texinfo
>> @@ -836,6 +836,11 @@ 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.
>>
>> +@findex thread-exited@r{, annotation}
>> +@item ^Z^Zthread-exited
>> +
>> +This annotation is issued once for each thread that exits.
>> +
>>  @end table
>
> In any case, the documentation should describe the format and 
> meaning of
> information passed with the annotation.
>
>> +proc thread_exit {} {
>> +    gdb_test_multiple "call (void)pthread_exit()" "thread 
>> exit" {
>> +	-re ".*\032\032thread-exited.*" {
>> +	    pass "thread exit"
>> +	}
>> +    }
>> +}
>
> Please enhance the regex to include the extra information, like 
> (untested):
>
>   -re 
>   ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\""
>
> Simon


--
Amos Bird
amosbird@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-thread-exit-annotation.patch --]
[-- Type: text/x-patch, Size: 4292 bytes --]

From 97bdfdccbd81f4fc056ac24b373e22b991b2fae1 Mon Sep 17 00:00:00 2001
From: Amos Bird <amosbird@gmail.com>
Date: Fri, 17 May 2019 21:23:09 +0800
Subject: [PATCH] Add "thread-exit" annotation.

---
 gdb/ChangeLog                      |  5 +++++
 gdb/NEWS                           |  2 ++
 gdb/annotate.c                     | 14 ++++++++++++++
 gdb/doc/ChangeLog                  |  5 +++++
 gdb/doc/annotate.texinfo           |  7 +++++++
 gdb/testsuite/ChangeLog            |  5 +++++
 gdb/testsuite/gdb.base/annota1.exp |  9 +++++++++
 7 files changed, 47 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0120e7743..849ed30731 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.c (annotate_thread_exited): Add "thread-exited"
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/NEWS b/gdb/NEWS
index 5309a8f923..735d915ec6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,8 @@
 
 *** Changes since GDB 8.3
 
+* 'thread-exited' event is now available in the annotations interface.
+
 * New built-in convenience variables $_gdb_major and $_gdb_minor
   provide the GDB version.  They are handy for conditionally using
   features available only in or since specific GDB versions, in
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 97cb4c8855..af804ddd1f 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -241,6 +241,19 @@ annotate_thread_changed (void)
     }
 }
 
+/* Emit notification on thread exit.  */
+
+static void
+annotate_thread_exited (struct thread_info *t, int silent)
+{
+  if (annotation_level > 1)
+    {
+      printf_filtered(("\n\032\032thread-exited,"
+                       "id=\"%d\",group-id=\"i%d\"\n"),
+                      t->global_num, t->inf->num);
+    }
+}
+
 void
 annotate_field_begin (struct type *type)
 {
@@ -595,4 +608,5 @@ _initialize_annotate (void)
   gdb::observers::breakpoint_created.attach (breakpoint_changed);
   gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
   gdb::observers::breakpoint_modified.attach (breakpoint_changed);
+  gdb::observers::thread_exit.attach (annotate_thread_exited);
 }
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ba152329d7..79b837aac6 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
+	annotation.
+
 2019-04-22  Pedro Alves  <palves@redhat.com>
 
 	* gdb.texinfo (Reverse Execution): Mention and xref process record
diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
index b85b759f9a..ee8147f52f 100644
--- a/gdb/doc/annotate.texinfo
+++ b/gdb/doc/annotate.texinfo
@@ -836,6 +836,13 @@ 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.
 
+@findex thread-exited@r{, annotation}
+@item ^Z^Zthread-exited,id="@var{id}",group-id="@var{gid}"
+
+This annotation is issued once for each thread that exits.  The @var{id}
+field contains the global @value{GDBN} identifier of the thread.  The
+@var{gid} field identifies the thread group this thread belongs to.
+
 @end table
 
 @node GNU Free Documentation License
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9b0725a033..d7a9b5611d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* gdb.base/annota1.exp (thread_switch): Add test for
+	thread-exited annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
index 5237bc9715..556e97b18b 100644
--- a/gdb/testsuite/gdb.base/annota1.exp
+++ b/gdb/testsuite/gdb.base/annota1.exp
@@ -492,8 +492,17 @@ proc thread_switch {} {
     }
 }
 
+proc thread_exit {} {
+    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {
+	-re ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" {
+	    pass "thread exit"
+	}
+    }
+}
+
 thread_test
 thread_switch
+thread_exit
 
 # restore the original prompt for the rest of the testsuite
 
-- 
2.21.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-17 13:23               ` Amos Bird
@ 2019-05-17 14:22                 ` Simon Marchi
  2019-05-17 15:50                   ` Amos Bird
  0 siblings, 1 reply; 19+ messages in thread
From: Simon Marchi @ 2019-05-17 14:22 UTC (permalink / raw)
  To: Amos Bird; +Cc: Eli Zaretskii, gbenson, gdb-patches, tom

On 2019-05-17 9:24 a.m., Amos Bird wrote:
> 
> Hi Simon,
> 
>> I don't mind if we start using MI-like syntax for annotation parameters, but it should
>> be a conscious decision to do so.
> 
> To be honest I don't use the extra information at all in cgdb, only "thread-exited". So
> I'm OK to whatever format it ends up to have.
> 
> Patch updated, thanks!

The test fails here, please verify that the it passes using:

  gdb/ $ make check TESTS="gdb.base/annota1.exp"

You'll need at least to declare "global decimal" to be able to access the decimal variable.
When adding that, I get a FAIL that I don't get without the patch applied:

FAIL: gdb.base/annota1.exp: signal sent (timeout)

Any interesting output will end up in testsuite/gdb.log.

Simon

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-17 14:22                 ` Simon Marchi
@ 2019-05-17 15:50                   ` Amos Bird
  2019-05-17 16:26                     ` Pedro Alves
  0 siblings, 1 reply; 19+ messages in thread
From: Amos Bird @ 2019-05-17 15:50 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Eli Zaretskii, gbenson, gdb-patches, tom

[-- Attachment #1: Type: text/plain, Size: 905 bytes --]


Fixed and updated patch. Thanks!

Simon Marchi <simark@simark.ca> writes:

> On 2019-05-17 9:24 a.m., Amos Bird wrote:
>>
>> Hi Simon,
>>
>>> I don't mind if we start using MI-like syntax for annotation 
>>> parameters, but it should
>>> be a conscious decision to do so.
>>
>> To be honest I don't use the extra information at all in cgdb, 
>> only "thread-exited". So
>> I'm OK to whatever format it ends up to have.
>>
>> Patch updated, thanks!
>
> The test fails here, please verify that the it passes using:
>
>   gdb/ $ make check TESTS="gdb.base/annota1.exp"
>
> You'll need at least to declare "global decimal" to be able to 
> access the decimal variable.
> When adding that, I get a FAIL that I don't get without the 
> patch applied:
>
> FAIL: gdb.base/annota1.exp: signal sent (timeout)
>
> Any interesting output will end up in testsuite/gdb.log.
>
> Simon


--
Amos Bird
amosbird@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-thread-exit-annotation.patch --]
[-- Type: text/x-patch, Size: 5420 bytes --]

From 7da413c7e6a2d7bb68fb66bcefb1679cdd7ba2fa Mon Sep 17 00:00:00 2001
From: Amos Bird <amosbird@gmail.com>
Date: Fri, 17 May 2019 21:23:09 +0800
Subject: [PATCH] Add "thread-exit" annotation.

---
 gdb/ChangeLog                      |  5 +++++
 gdb/NEWS                           |  2 ++
 gdb/annotate.c                     | 14 ++++++++++++++
 gdb/doc/ChangeLog                  |  5 +++++
 gdb/doc/annotate.texinfo           |  7 +++++++
 gdb/testsuite/ChangeLog            |  5 +++++
 gdb/testsuite/gdb.base/annota1.exp | 12 +++++++++++-
 7 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0120e7743..849ed30731 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.c (annotate_thread_exited): Add "thread-exited"
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/NEWS b/gdb/NEWS
index 5309a8f923..735d915ec6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,8 @@
 
 *** Changes since GDB 8.3
 
+* 'thread-exited' event is now available in the annotations interface.
+
 * New built-in convenience variables $_gdb_major and $_gdb_minor
   provide the GDB version.  They are handy for conditionally using
   features available only in or since specific GDB versions, in
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 97cb4c8855..af804ddd1f 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -241,6 +241,19 @@ annotate_thread_changed (void)
     }
 }
 
+/* Emit notification on thread exit.  */
+
+static void
+annotate_thread_exited (struct thread_info *t, int silent)
+{
+  if (annotation_level > 1)
+    {
+      printf_filtered(("\n\032\032thread-exited,"
+                       "id=\"%d\",group-id=\"i%d\"\n"),
+                      t->global_num, t->inf->num);
+    }
+}
+
 void
 annotate_field_begin (struct type *type)
 {
@@ -595,4 +608,5 @@ _initialize_annotate (void)
   gdb::observers::breakpoint_created.attach (breakpoint_changed);
   gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
   gdb::observers::breakpoint_modified.attach (breakpoint_changed);
+  gdb::observers::thread_exit.attach (annotate_thread_exited);
 }
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ba152329d7..79b837aac6 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
+	annotation.
+
 2019-04-22  Pedro Alves  <palves@redhat.com>
 
 	* gdb.texinfo (Reverse Execution): Mention and xref process record
diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
index b85b759f9a..ee8147f52f 100644
--- a/gdb/doc/annotate.texinfo
+++ b/gdb/doc/annotate.texinfo
@@ -836,6 +836,13 @@ 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.
 
+@findex thread-exited@r{, annotation}
+@item ^Z^Zthread-exited,id="@var{id}",group-id="@var{gid}"
+
+This annotation is issued once for each thread that exits.  The @var{id}
+field contains the global @value{GDBN} identifier of the thread.  The
+@var{gid} field identifies the thread group this thread belongs to.
+
 @end table
 
 @node GNU Free Documentation License
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9b0725a033..d7a9b5611d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* gdb.base/annota1.exp (thread_switch): Add test for
+	thread-exited annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
index 5237bc9715..25ed1dc439 100644
--- a/gdb/testsuite/gdb.base/annota1.exp
+++ b/gdb/testsuite/gdb.base/annota1.exp
@@ -428,7 +428,7 @@ if [target_info exists gdb,nosignals] {
     unsupported "signal sent"
 } else {
     gdb_test_multiple "signal SIGTRAP" "signal sent" {
-	-re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
+-re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
 	    pass "signal sent"
 	}
     }
@@ -492,8 +492,18 @@ proc thread_switch {} {
     }
 }
 
+proc thread_exit {} {
+    global decimal
+    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {
+	-re ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" {
+	    pass "thread exit"
+	}
+    }
+}
+
 thread_test
 thread_switch
+thread_exit
 
 # restore the original prompt for the rest of the testsuite
 
-- 
2.21.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-17 15:50                   ` Amos Bird
@ 2019-05-17 16:26                     ` Pedro Alves
  2019-05-17 17:13                       ` Amos Bird
  0 siblings, 1 reply; 19+ messages in thread
From: Pedro Alves @ 2019-05-17 16:26 UTC (permalink / raw)
  To: Amos Bird, Simon Marchi; +Cc: Eli Zaretskii, gbenson, gdb-patches, tom

On 5/17/19 4:51 PM, Amos Bird wrote:
> +proc thread_exit {} {
> +    global decimal
> +    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {

Since this is calling a function, it would need to be gated
with a gdb,cannot_call_functions check (grep for uses).

Does that call return?  If the thread exits, the "call" command will
continue running without returning to the prompt, right?  

I guess that's why you don't expect the prompt here:

> +    gdb_test_multiple "call (void)pthread_exit()" "thread exit" {
> +	-re ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" {
> +	    pass "thread exit"
> +	}
> +    }
> +}

Note that this approach means that if someone were to add a test
after this one, we'd need to either ctrl-c the program, or restart
gdb.

Please test this with

 make check RUNTESTFLAGS="--target_board=native-gdbserver"

too.  In that case, you're debugging with gdbserver, and gdb/gdbserver
won't notice that the thread exited until the program next stops.

Also, you probably don't have debug info for glibc/libpthread in your
system.  I say this because pthread_exit takes an argument and above
you're not passing any, resulting in undefined behavior.

I'd be much better if the .c file were tweaked to make the thread
exit on its own, or a new .c file were added for that purpose, IMO.
E.g., make the main thread join a child thread and hit a breakpoint
once the thread exits and the join unlocks.

> +	-re ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" {
> +	    pass "thread exit"
> +	}
> +    }
> +}
> +
>  thread_test
>  thread_switch
> +thread_exit
>  
>  # restore the original prompt for the rest of the testsuite

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-17 16:26                     ` Pedro Alves
@ 2019-05-17 17:13                       ` Amos Bird
  2019-06-06 15:37                         ` Amos Bird
  2019-06-06 16:32                         ` Pedro Alves
  0 siblings, 2 replies; 19+ messages in thread
From: Amos Bird @ 2019-05-17 17:13 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, Eli Zaretskii, gbenson, gdb-patches, tom

[-- Attachment #1: Type: text/plain, Size: 1977 bytes --]


Hi Pedro,

Thanks for the suggestion. Patch updated.

Amos

Pedro Alves <palves@redhat.com> writes:

> On 5/17/19 4:51 PM, Amos Bird wrote:
>> +proc thread_exit {} {
>> +    global decimal
>> +    gdb_test_multiple "call (void)pthread_exit()" "thread 
>> exit" {
>
> Since this is calling a function, it would need to be gated
> with a gdb,cannot_call_functions check (grep for uses).
>
> Does that call return?  If the thread exits, the "call" command 
> will
> continue running without returning to the prompt, right?
>
> I guess that's why you don't expect the prompt here:
>
>> +    gdb_test_multiple "call (void)pthread_exit()" "thread 
>> exit" {
>> +	-re 
>> ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" 
>> {
>> +	    pass "thread exit"
>> +	}
>> +    }
>> +}
>
> Note that this approach means that if someone were to add a test
> after this one, we'd need to either ctrl-c the program, or 
> restart
> gdb.
>
> Please test this with
>
>  make check RUNTESTFLAGS="--target_board=native-gdbserver"
>
> too.  In that case, you're debugging with gdbserver, and 
> gdb/gdbserver
> won't notice that the thread exited until the program next 
> stops.
>
> Also, you probably don't have debug info for glibc/libpthread in 
> your
> system.  I say this because pthread_exit takes an argument and 
> above
> you're not passing any, resulting in undefined behavior.
>
> I'd be much better if the .c file were tweaked to make the 
> thread
> exit on its own, or a new .c file were added for that purpose, 
> IMO.
> E.g., make the main thread join a child thread and hit a 
> breakpoint
> once the thread exits and the join unlocks.
>
>> +	-re 
>> ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" 
>> {
>> +	    pass "thread exit"
>> +	}
>> +    }
>> +}
>> +
>>  thread_test
>>  thread_switch
>> +thread_exit
>>
>>  # restore the original prompt for the rest of the testsuite
>
> Thanks,
> Pedro Alves


--
Amos Bird
amosbird@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-thread-exit-annotation.patch --]
[-- Type: text/x-patch, Size: 7706 bytes --]

From 8fc6ecff07b2202f6d89802ee7686ee373732e1c Mon Sep 17 00:00:00 2001
From: Amos Bird <amosbird@gmail.com>
Date: Fri, 17 May 2019 21:23:09 +0800
Subject: [PATCH] Add "thread-exit" annotation.

---
 gdb/ChangeLog                             |  5 +++++
 gdb/NEWS                                  |  2 ++
 gdb/annotate.c                            | 14 +++++++++++++
 gdb/doc/ChangeLog                         |  5 +++++
 gdb/doc/annotate.texinfo                  |  7 +++++++
 gdb/testsuite/ChangeLog                   |  5 +++++
 gdb/testsuite/gdb.base/annota1.exp        | 12 ++++++++++-
 gdb/testsuite/gdb.base/watch_thread_num.c | 25 +++++++++++++++++------
 8 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0120e7743..849ed30731 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.c (annotate_thread_exited): Add "thread-exited"
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/NEWS b/gdb/NEWS
index 5309a8f923..735d915ec6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,8 @@
 
 *** Changes since GDB 8.3
 
+* 'thread-exited' event is now available in the annotations interface.
+
 * New built-in convenience variables $_gdb_major and $_gdb_minor
   provide the GDB version.  They are handy for conditionally using
   features available only in or since specific GDB versions, in
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 97cb4c8855..af804ddd1f 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -241,6 +241,19 @@ annotate_thread_changed (void)
     }
 }
 
+/* Emit notification on thread exit.  */
+
+static void
+annotate_thread_exited (struct thread_info *t, int silent)
+{
+  if (annotation_level > 1)
+    {
+      printf_filtered(("\n\032\032thread-exited,"
+                       "id=\"%d\",group-id=\"i%d\"\n"),
+                      t->global_num, t->inf->num);
+    }
+}
+
 void
 annotate_field_begin (struct type *type)
 {
@@ -595,4 +608,5 @@ _initialize_annotate (void)
   gdb::observers::breakpoint_created.attach (breakpoint_changed);
   gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
   gdb::observers::breakpoint_modified.attach (breakpoint_changed);
+  gdb::observers::thread_exit.attach (annotate_thread_exited);
 }
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ba152329d7..79b837aac6 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
+	annotation.
+
 2019-04-22  Pedro Alves  <palves@redhat.com>
 
 	* gdb.texinfo (Reverse Execution): Mention and xref process record
diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
index b85b759f9a..ee8147f52f 100644
--- a/gdb/doc/annotate.texinfo
+++ b/gdb/doc/annotate.texinfo
@@ -836,6 +836,13 @@ 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.
 
+@findex thread-exited@r{, annotation}
+@item ^Z^Zthread-exited,id="@var{id}",group-id="@var{gid}"
+
+This annotation is issued once for each thread that exits.  The @var{id}
+field contains the global @value{GDBN} identifier of the thread.  The
+@var{gid} field identifies the thread group this thread belongs to.
+
 @end table
 
 @node GNU Free Documentation License
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9b0725a033..d7a9b5611d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* gdb.base/annota1.exp (thread_switch): Add test for
+	thread-exited annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
index 5237bc9715..4e4e8439fb 100644
--- a/gdb/testsuite/gdb.base/annota1.exp
+++ b/gdb/testsuite/gdb.base/annota1.exp
@@ -428,7 +428,7 @@ if [target_info exists gdb,nosignals] {
     unsupported "signal sent"
 } else {
     gdb_test_multiple "signal SIGTRAP" "signal sent" {
-	-re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
+-re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
 	    pass "signal sent"
 	}
     }
@@ -450,6 +450,7 @@ if { [remote_file host exists core] } {
 proc thread_test {} {
     global subdir srcdir testfile srcfile binfile
     global gdb_prompt old_gdb_prompt
+    global decimal
     set srcfile watch_thread_num.c
     set binfile [standard_output_file ${testfile}-watch_thread_num]
     set gdb_prompt $old_gdb_prompt
@@ -468,6 +469,9 @@ proc thread_test {} {
 	set linenum [gdb_get_line_number "all threads started"]
 	gdb_breakpoint "$linenum"
 
+	set linenum [gdb_get_line_number "first child thread exited"]
+	gdb_breakpoint "$linenum"
+
 	set gdb_prompt \
 	    "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
 
@@ -481,6 +485,12 @@ proc thread_test {} {
 		pass "new thread"
 	    }
 	}
+
+    gdb_test_multiple "continue" "thread exit" {
+		-re "\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" {
+			pass "thread exit"
+		}
+    }
     }
 }
 
diff --git a/gdb/testsuite/gdb.base/watch_thread_num.c b/gdb/testsuite/gdb.base/watch_thread_num.c
index a5195c71f6..fe9d602476 100644
--- a/gdb/testsuite/gdb.base/watch_thread_num.c
+++ b/gdb/testsuite/gdb.base/watch_thread_num.c
@@ -29,6 +29,8 @@ void *thread_function (void *arg); /* Pointer to function executed by each threa
 
 static pthread_barrier_t threads_started_barrier;
 
+static pthread_barrier_t threads_started_barrier2;
+
 #define NUM 15
 
 static int num_threads = NUM;
@@ -43,6 +45,8 @@ int main () {
 
     pthread_barrier_init (&threads_started_barrier, NULL, NUM + 1);
 
+    pthread_barrier_init (&threads_started_barrier2, NULL, 2);
+
     for (i = 0; i < NUM; i++)
       {
         res = pthread_create (&threads[i],
@@ -53,7 +57,11 @@ int main () {
 
     pthread_barrier_wait (&threads_started_barrier);
 
-    sleep (180); /* all threads started */
+    pthread_barrier_wait (&threads_started_barrier2);  /* all threads started */
+
+    pthread_join (threads[0], NULL);
+
+    sleep (180);  /* first child thread exited */
 
     exit (EXIT_SUCCESS);
 }
@@ -68,13 +76,18 @@ void *thread_function (void *arg) {
 
     pthread_barrier_wait (&threads_started_barrier);
 
-    /* Don't run forever.  Run just short of it :)  */
-    while (shared_var > 0)
+    if (my_number > 0)
       {
-        shared_var++;
-	usleep (1); /* Loop increment.  */
-	loop ();
+	/* Don't run forever.  Run just short of it :)  */
+	while (shared_var > 0)
+	  {
+	    shared_var++;
+	    usleep (1); /* Loop increment.  */
+	    loop ();
+	  }
       }
+    else
+      pthread_barrier_wait (&threads_started_barrier2);
 
     pthread_exit (NULL);
 }
-- 
2.21.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-17 17:13                       ` Amos Bird
@ 2019-06-06 15:37                         ` Amos Bird
  2019-06-06 16:32                         ` Pedro Alves
  1 sibling, 0 replies; 19+ messages in thread
From: Amos Bird @ 2019-06-06 15:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves, Simon Marchi, Eli Zaretskii, gbenson, tom


Gentle ping.

Thanks!

Amos Bird <amosbird@gmail.com> writes:

> Hi Pedro,
>
> Thanks for the suggestion. Patch updated.
>
> Amos
>
> Pedro Alves <palves@redhat.com> writes:
>
>> On 5/17/19 4:51 PM, Amos Bird wrote:
>>> +proc thread_exit {} {
>>> +    global decimal
>>> +    gdb_test_multiple "call (void)pthread_exit()" "thread
>>> exit" {
>>
>> Since this is calling a function, it would need to be gated
>> with a gdb,cannot_call_functions check (grep for uses).
>>
>> Does that call return?  If the thread exits, the "call" command
>> will
>> continue running without returning to the prompt, right?
>>
>> I guess that's why you don't expect the prompt here:
>>
>>> +    gdb_test_multiple "call (void)pthread_exit()" "thread
>>> exit" {
>>> +	-re
>>> ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\""
>>> {
>>> +	    pass "thread exit"
>>> +	}
>>> +    }
>>> +}
>>
>> Note that this approach means that if someone were to add a 
>> test
>> after this one, we'd need to either ctrl-c the program, or
>> restart
>> gdb.
>>
>> Please test this with
>>
>>  make check RUNTESTFLAGS="--target_board=native-gdbserver"
>>
>> too.  In that case, you're debugging with gdbserver, and
>> gdb/gdbserver
>> won't notice that the thread exited until the program next
>> stops.
>>
>> Also, you probably don't have debug info for glibc/libpthread 
>> in
>> your
>> system.  I say this because pthread_exit takes an argument and
>> above
>> you're not passing any, resulting in undefined behavior.
>>
>> I'd be much better if the .c file were tweaked to make the
>> thread
>> exit on its own, or a new .c file were added for that purpose,
>> IMO.
>> E.g., make the main thread join a child thread and hit a
>> breakpoint
>> once the thread exits and the join unlocks.
>>
>>> +	-re
>>> ".*\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\""
>>> {
>>> +	    pass "thread exit"
>>> +	}
>>> +    }
>>> +}
>>> +
>>>  thread_test
>>>  thread_switch
>>> +thread_exit
>>>
>>>  # restore the original prompt for the rest of the testsuite
>>
>> Thanks,
>> Pedro Alves


--
Amos Bird
amosbird@gmail.com

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-05-17 17:13                       ` Amos Bird
  2019-06-06 15:37                         ` Amos Bird
@ 2019-06-06 16:32                         ` Pedro Alves
  2019-06-06 17:11                           ` Amos Bird
  1 sibling, 1 reply; 19+ messages in thread
From: Pedro Alves @ 2019-06-06 16:32 UTC (permalink / raw)
  To: Amos Bird; +Cc: Simon Marchi, Eli Zaretskii, gbenson, gdb-patches, tom

On 5/17/19 6:14 PM, Amos Bird wrote:
>  } else {
>      gdb_test_multiple "signal SIGTRAP" "signal sent" {
> -	-re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
> +-re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
>  	    pass "signal sent"

That lost the tab before "-re" -- was that on purpose?


>  	}
>      }
> @@ -450,6 +450,7 @@ if { [remote_file host exists core] } {
>  proc thread_test {} {
>      global subdir srcdir testfile srcfile binfile
>      global gdb_prompt old_gdb_prompt
> +    global decimal
>      set srcfile watch_thread_num.c
>      set binfile [standard_output_file ${testfile}-watch_thread_num]
>      set gdb_prompt $old_gdb_prompt
> @@ -468,6 +469,9 @@ proc thread_test {} {
>  	set linenum [gdb_get_line_number "all threads started"]
>  	gdb_breakpoint "$linenum"
>  
> +	set linenum [gdb_get_line_number "first child thread exited"]
> +	gdb_breakpoint "$linenum"
> +
>  	set gdb_prompt \
>  	    "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
>  
> @@ -481,6 +485,12 @@ proc thread_test {} {
>  		pass "new thread"
>  	    }
>  	}
> +
> +    gdb_test_multiple "continue" "thread exit" {
> +		-re "\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" {
> +			pass "thread exit"
> +		}
> +    }

This should use the same indentation levels as the similar code above.

Also, this isn't expecting the prompt.  Is there a reason for that?
Not matching/expecting the prompt is usually not desired, because it
leaves the prompt in the expect buffer, which can confuse following
tests.

Also, this causes some regressions:

 Running src/gdb/testsuite/gdb.cp/annota2.exp ...
 FAIL: gdb.cp/annota2.exp: continue until exit (timeout)
 FAIL: gdb.cp/annota2.exp: delete bps
 FAIL: gdb.cp/annota2.exp: break at main (got interactive prompt)

Please take a look at those and make sure to run the whole
testsuite (I only ran the "gdb.*/annota*.exp" tests).

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-06-06 16:32                         ` Pedro Alves
@ 2019-06-06 17:11                           ` Amos Bird
  2019-06-06 17:37                             ` Tom Tromey
  0 siblings, 1 reply; 19+ messages in thread
From: Amos Bird @ 2019-06-06 17:11 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, Eli Zaretskii, gbenson, gdb-patches, tom

[-- Attachment #1: Type: text/plain, Size: 2979 bytes --]


Updated. Thanks!

Pedro Alves <palves@redhat.com> writes:

> On 5/17/19 6:14 PM, Amos Bird wrote:
>>  } else {
>>      gdb_test_multiple "signal SIGTRAP" "signal sent" {
>> -	-re ".*\032\032post-prompt\r\nContinuing with signal 
>> SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram 
>> terminated with signal 
>> \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, 
>> \r\n\032\032signal-string\r\nTrace.breakpoint 
>> trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer 
>> exists.\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
>> +-re ".*\032\032post-prompt\r\nContinuing with signal 
>> SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram 
>> terminated with signal 
>> \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, 
>> \r\n\032\032signal-string\r\nTrace.breakpoint 
>> trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer 
>> exists.\r\n\r\n\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"\r\n\r\n\032\032stopped\r\n$gdb_prompt$" 
>> {
>>  	    pass "signal sent"
>
> That lost the tab before "-re" -- was that on purpose?
>
>
>>  	}
>>      }
>> @@ -450,6 +450,7 @@ if { [remote_file host exists core] } {
>>  proc thread_test {} {
>>      global subdir srcdir testfile srcfile binfile
>>      global gdb_prompt old_gdb_prompt
>> +    global decimal
>>      set srcfile watch_thread_num.c
>>      set binfile [standard_output_file 
>>      ${testfile}-watch_thread_num]
>>      set gdb_prompt $old_gdb_prompt
>> @@ -468,6 +469,9 @@ proc thread_test {} {
>>  	set linenum [gdb_get_line_number "all threads started"]
>>  	gdb_breakpoint "$linenum"
>>
>> +	set linenum [gdb_get_line_number "first child thread 
>> exited"]
>> +	gdb_breakpoint "$linenum"
>> +
>>  	set gdb_prompt \
>>  	    "\r\n\032\032pre-prompt\r\n$gdb_prompt 
>>  \r\n\032\032prompt\r\n"
>>
>> @@ -481,6 +485,12 @@ proc thread_test {} {
>>  		pass "new thread"
>>  	    }
>>  	}
>> +
>> +    gdb_test_multiple "continue" "thread exit" {
>> +		-re 
>> "\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"" 
>> {
>> +			pass "thread exit"
>> +		}
>> +    }
>
> This should use the same indentation levels as the similar code 
> above.
>
> Also, this isn't expecting the prompt.  Is there a reason for 
> that?
> Not matching/expecting the prompt is usually not desired, 
> because it
> leaves the prompt in the expect buffer, which can confuse 
> following
> tests.
>
> Also, this causes some regressions:
>
>  Running src/gdb/testsuite/gdb.cp/annota2.exp ...
>  FAIL: gdb.cp/annota2.exp: continue until exit (timeout)
>  FAIL: gdb.cp/annota2.exp: delete bps
>  FAIL: gdb.cp/annota2.exp: break at main (got interactive 
>  prompt)
>
> Please take a look at those and make sure to run the whole
> testsuite (I only ran the "gdb.*/annota*.exp" tests).
>
> Thanks,
> Pedro Alves


--
Amos Bird
amosbird@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-thread-exit-annotation.patch --]
[-- Type: text/x-patch, Size: 8271 bytes --]

From 68d708fb2f25d3c635be0429b54792970313ac9d Mon Sep 17 00:00:00 2001
From: Amos Bird <amosbird@gmail.com>
Date: Fri, 7 Jun 2019 01:10:14 +0800
Subject: [PATCH] Add thread-exit annotation.

---
 gdb/ChangeLog                             |  5 +++++
 gdb/NEWS                                  |  2 ++
 gdb/annotate.c                            | 14 +++++++++++++
 gdb/doc/ChangeLog                         |  5 +++++
 gdb/doc/annotate.texinfo                  |  7 +++++++
 gdb/testsuite/ChangeLog                   |  5 +++++
 gdb/testsuite/gdb.base/annota1.exp        | 12 ++++++++++-
 gdb/testsuite/gdb.base/watch_thread_num.c | 25 +++++++++++++++++------
 gdb/testsuite/gdb.cp/annota2.exp          |  2 ++
 9 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e0120e7743..849ed30731 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.c (annotate_thread_exited): Add "thread-exited"
+	annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/NEWS b/gdb/NEWS
index 5309a8f923..735d915ec6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,8 @@
 
 *** Changes since GDB 8.3
 
+* 'thread-exited' event is now available in the annotations interface.
+
 * New built-in convenience variables $_gdb_major and $_gdb_minor
   provide the GDB version.  They are handy for conditionally using
   features available only in or since specific GDB versions, in
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 97cb4c8855..af804ddd1f 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -241,6 +241,19 @@ annotate_thread_changed (void)
     }
 }
 
+/* Emit notification on thread exit.  */
+
+static void
+annotate_thread_exited (struct thread_info *t, int silent)
+{
+  if (annotation_level > 1)
+    {
+      printf_filtered(("\n\032\032thread-exited,"
+                       "id=\"%d\",group-id=\"i%d\"\n"),
+                      t->global_num, t->inf->num);
+    }
+}
+
 void
 annotate_field_begin (struct type *type)
 {
@@ -595,4 +608,5 @@ _initialize_annotate (void)
   gdb::observers::breakpoint_created.attach (breakpoint_changed);
   gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
   gdb::observers::breakpoint_modified.attach (breakpoint_changed);
+  gdb::observers::thread_exit.attach (annotate_thread_exited);
 }
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ba152329d7..79b837aac6 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
+	annotation.
+
 2019-04-22  Pedro Alves  <palves@redhat.com>
 
 	* gdb.texinfo (Reverse Execution): Mention and xref process record
diff --git a/gdb/doc/annotate.texinfo b/gdb/doc/annotate.texinfo
index b85b759f9a..ee8147f52f 100644
--- a/gdb/doc/annotate.texinfo
+++ b/gdb/doc/annotate.texinfo
@@ -836,6 +836,13 @@ 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.
 
+@findex thread-exited@r{, annotation}
+@item ^Z^Zthread-exited,id="@var{id}",group-id="@var{gid}"
+
+This annotation is issued once for each thread that exits.  The @var{id}
+field contains the global @value{GDBN} identifier of the thread.  The
+@var{gid} field identifies the thread group this thread belongs to.
+
 @end table
 
 @node GNU Free Documentation License
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9b0725a033..d7a9b5611d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-26  Amos Bird  <amosbird@gmail.com>
+
+	* gdb.base/annota1.exp (thread_switch): Add test for
+	thread-exited annotation.
+
 2019-04-25  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/24367
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
index 5237bc9715..dfa30831e6 100644
--- a/gdb/testsuite/gdb.base/annota1.exp
+++ b/gdb/testsuite/gdb.base/annota1.exp
@@ -428,7 +428,7 @@ if [target_info exists gdb,nosignals] {
     unsupported "signal sent"
 } else {
     gdb_test_multiple "signal SIGTRAP" "signal sent" {
-	-re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
+	-re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"\r\n\r\n\032\032stopped\r\n$gdb_prompt$" {
 	    pass "signal sent"
 	}
     }
@@ -450,6 +450,7 @@ if { [remote_file host exists core] } {
 proc thread_test {} {
     global subdir srcdir testfile srcfile binfile
     global gdb_prompt old_gdb_prompt
+    global decimal
     set srcfile watch_thread_num.c
     set binfile [standard_output_file ${testfile}-watch_thread_num]
     set gdb_prompt $old_gdb_prompt
@@ -468,6 +469,9 @@ proc thread_test {} {
 	set linenum [gdb_get_line_number "all threads started"]
 	gdb_breakpoint "$linenum"
 
+	set linenum [gdb_get_line_number "first child thread exited"]
+	gdb_breakpoint "$linenum"
+
 	set gdb_prompt \
 	    "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
 
@@ -481,6 +485,12 @@ proc thread_test {} {
 		pass "new thread"
 	    }
 	}
+
+    gdb_test_multiple "continue" "thread exit" {
+	    -re "\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\".*\r\n$gdb_prompt$" {
+		pass "thread exit"
+	    }
+    }
     }
 }
 
diff --git a/gdb/testsuite/gdb.base/watch_thread_num.c b/gdb/testsuite/gdb.base/watch_thread_num.c
index a5195c71f6..fe9d602476 100644
--- a/gdb/testsuite/gdb.base/watch_thread_num.c
+++ b/gdb/testsuite/gdb.base/watch_thread_num.c
@@ -29,6 +29,8 @@ void *thread_function (void *arg); /* Pointer to function executed by each threa
 
 static pthread_barrier_t threads_started_barrier;
 
+static pthread_barrier_t threads_started_barrier2;
+
 #define NUM 15
 
 static int num_threads = NUM;
@@ -43,6 +45,8 @@ int main () {
 
     pthread_barrier_init (&threads_started_barrier, NULL, NUM + 1);
 
+    pthread_barrier_init (&threads_started_barrier2, NULL, 2);
+
     for (i = 0; i < NUM; i++)
       {
         res = pthread_create (&threads[i],
@@ -53,7 +57,11 @@ int main () {
 
     pthread_barrier_wait (&threads_started_barrier);
 
-    sleep (180); /* all threads started */
+    pthread_barrier_wait (&threads_started_barrier2);  /* all threads started */
+
+    pthread_join (threads[0], NULL);
+
+    sleep (180);  /* first child thread exited */
 
     exit (EXIT_SUCCESS);
 }
@@ -68,13 +76,18 @@ void *thread_function (void *arg) {
 
     pthread_barrier_wait (&threads_started_barrier);
 
-    /* Don't run forever.  Run just short of it :)  */
-    while (shared_var > 0)
+    if (my_number > 0)
       {
-        shared_var++;
-	usleep (1); /* Loop increment.  */
-	loop ();
+	/* Don't run forever.  Run just short of it :)  */
+	while (shared_var > 0)
+	  {
+	    shared_var++;
+	    usleep (1); /* Loop increment.  */
+	    loop ();
+	  }
       }
+    else
+      pthread_barrier_wait (&threads_started_barrier2);
 
     pthread_exit (NULL);
 }
diff --git a/gdb/testsuite/gdb.cp/annota2.exp b/gdb/testsuite/gdb.cp/annota2.exp
index 982020a11e..745f461716 100644
--- a/gdb/testsuite/gdb.cp/annota2.exp
+++ b/gdb/testsuite/gdb.cp/annota2.exp
@@ -138,6 +138,8 @@ set pat [multi_line "" \
 	     "\032\032exited 0" \
 	     "$inferior_exited_re normally." \
 	     "" \
+	     "\032\032thread-exited,id=\"1\",group-id=\"i1\"" \
+	     "" \
 	     "\032\032stopped" \
 	     $gdb_prompt$]
 gdb_test_multiple "continue" "continue until exit" {
-- 
2.21.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Add "thread-exited" annotation
  2019-06-06 17:11                           ` Amos Bird
@ 2019-06-06 17:37                             ` Tom Tromey
  0 siblings, 0 replies; 19+ messages in thread
From: Tom Tromey @ 2019-06-06 17:37 UTC (permalink / raw)
  To: Amos Bird
  Cc: Pedro Alves, Simon Marchi, Eli Zaretskii, gbenson, gdb-patches, tom

>>>>> "Amos" == Amos Bird <amosbird@gmail.com> writes:

Amos> Updated. Thanks!

I've checked this in.

Tom

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2019-06-06 17:37 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 15:19 [PATCH] Add "thread-exited" annotation Amos Bird
2019-04-30 15:45 ` Tom Tromey
2019-04-30 17:09   ` Amos Bird
2019-05-16 13:14     ` Gary Benson
2019-05-16 14:10       ` Amos Bird
2019-05-16 14:35         ` Eli Zaretskii
2019-05-16 14:45           ` Amos Bird
2019-05-17  9:59             ` Gary Benson
2019-05-17 10:55               ` Amos Bird
2019-05-17 13:08             ` Simon Marchi
2019-05-17 13:23               ` Amos Bird
2019-05-17 14:22                 ` Simon Marchi
2019-05-17 15:50                   ` Amos Bird
2019-05-17 16:26                     ` Pedro Alves
2019-05-17 17:13                       ` Amos Bird
2019-06-06 15:37                         ` Amos Bird
2019-06-06 16:32                         ` Pedro Alves
2019-06-06 17:11                           ` Amos Bird
2019-06-06 17:37                             ` Tom Tromey

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).