Fix inferior_thread attribute in new_thread event

Message ID 20220105154219.2018-1-ssbssa@yahoo.de
State New
Headers show
Series
  • Fix inferior_thread attribute in new_thread event
Related show

Commit Message

Simon Marchi via Gdb-patches Jan. 5, 2022, 3:42 p.m.
Commit 72ee03ff58 fixed a use-after-move bug in add_thread_object, but
it changed the inferior_thread attribute to contain the inferior instead
of the actual thread.
This now uses the thread_obj in its new location instead.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28429
---
 gdb/python/py-inferior.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.34.1

Comments

Simon Marchi via Gdb-patches Jan. 5, 2022, 4:58 p.m. | #1
* Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> [2022-01-05 16:42:19 +0100]:

> Commit 72ee03ff58 fixed a use-after-move bug in add_thread_object, but

> it changed the inferior_thread attribute to contain the inferior instead

> of the actual thread.

> This now uses the thread_obj in its new location instead.

> 

> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28429

> ---

>  gdb/python/py-inferior.c | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c

> index 39efa804d80..d6653e0acb4 100644

> --- a/gdb/python/py-inferior.c

> +++ b/gdb/python/py-inferior.c

> @@ -345,7 +345,8 @@ add_thread_object (struct thread_info *tp)

>      return;

>  

>    gdbpy_ref<> event = create_thread_event_object (&new_thread_event_object_type,

> -						  (PyObject *) inf_obj);

> +						  (PyObject *)

> +						  entry->thread_obj.get ());

>    if (event == NULL

>        || evpy_emit_event (event.get (), gdb_py_events.new_thread) < 0)

>      gdbpy_print_stack ();

> -- 

> 2.34.1

> 


This change looks good, but we try, as far as possible, to always
include a test with every GDB change.  Tests should be included in the
same commit as the change to GDB it at all possible.

In this case it's pretty easy, so I've included one below which you
can merge with the above change before pushing.

Thanks,
Andrew

---

diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
index b0747154ee0..5cbbe43c44c 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -31,7 +31,8 @@ gdb_test_multiline "install new_thread event handler" \
     "python" "" \
     "seen_a_thread = False" "" \
     "def thread_handler(evt):" "" \
-    "  if evt.inferior_thread is not None:" "" \
+    "  if (evt.inferior_thread is not None" "" \
+    "      and isinstance (evt.inferior_thread, gdb.InferiorThread)):" "" \
     "    global seen_a_thread" "" \
     "    seen_a_thread = True" "" \
     "gdb.events.new_thread.connect(thread_handler)" "" \
Simon Marchi via Gdb-patches Jan. 5, 2022, 5:33 p.m. | #2
Am Mittwoch, 5. Januar 2022, 17:59:07 MEZ hat Andrew Burgess <aburgess@redhat.com> Folgendes geschrieben:

> This change looks good, but we try, as far as possible, to always

> include a test with every GDB change.  Tests should be included in the

> same commit as the change to GDB it at all possible.

>

> In this case it's pretty easy, so I've included one below which you

> can merge with the above change before pushing.

>

> Thanks,

> Andrew

>

> ---

>

> diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp

> index b0747154ee0..5cbbe43c44c 100644

> --- a/gdb/testsuite/gdb.python/py-infthread.exp

> +++ b/gdb/testsuite/gdb.python/py-infthread.exp

> @@ -31,7 +31,8 @@ gdb_test_multiline "install new_thread event handler" \

>

>     "python" "" \

>

>     "seen_a_thread = False" "" \

>     "def thread_handler(evt):" "" \

> -    "  if evt.inferior_thread is not None:" "" \

> +    "  if (evt.inferior_thread is not None" "" \

> +    "      and isinstance (evt.inferior_thread, gdb.InferiorThread)):" "" \

>     "    global seen_a_thread" "" \

>     "    seen_a_thread = True" "" \

>     "gdb.events.new_thread.connect(thread_handler)" "" \


Pushed with this change, thanks.


Hannes

Patch

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 39efa804d80..d6653e0acb4 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -345,7 +345,8 @@  add_thread_object (struct thread_info *tp)
     return;
 
   gdbpy_ref<> event = create_thread_event_object (&new_thread_event_object_type,
-						  (PyObject *) inf_obj);
+						  (PyObject *)
+						  entry->thread_obj.get ());
   if (event == NULL
       || evpy_emit_event (event.get (), gdb_py_events.new_thread) < 0)
     gdbpy_print_stack ();