Add "thread-exited" annotation

Message ID 87ef4ypif5.fsf@gmail.com
State New, archived
Headers

Commit Message

Amos Bird May 16, 2019, 2:45 p.m. UTC
  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
  

Comments

Gary Benson May 17, 2019, 9:59 a.m. UTC | #1
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 May 17, 2019, 10:55 a.m. UTC | #2
> 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
  
Simon Marchi May 17, 2019, 1:08 p.m. UTC | #3
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
  

Patch

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