public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom de Vries <tdevries@suse.de>, Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCHv2 0/8] Python __repr__() methods and new __dict__ attributes
Date: Fri, 12 Jan 2024 16:20:33 +0000	[thread overview]
Message-ID: <87h6ji7cby.fsf@redhat.com> (raw)
In-Reply-To: <fe36f587-6642-469a-ae72-d71115cb366c@suse.de>

Tom de Vries <tdevries@suse.de> writes:

> On 1/12/24 14:44, Andrew Burgess wrote:
>> Tom Tromey <tom@tromey.com> writes:
>> 
>>>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>>>
>>> Andrew> In V2:
>>> Andrew>   - Fixed problems in thpy_dealloc that Tom pointed out,
>>>
>>> Andrew>   - Used @group...@end group in the docs as suggested by Eli,
>>>
>>> Andrew>   - Added patches #7 and #8, which are both docs only patches.  The
>>> Andrew>     first adds advice for naming attributes as Tom suggested, the
>>> Andrew>     second is just some doc updates that I noticed in passing.
>>>
>>> Thanks, this looks good & addresses my comments.
>>> Approved-By: Tom Tromey <tom@tromey.com>
>> 
>> Pushed.
>> 
>
> Hi Andrew,
>
> I'm seeing this new FAIL:
> ...
> FAIL: gdb.python/py-inferior.exp: test repr of an invalid thread
> ...
>
> Filed as https://sourceware.org/bugzilla/show_bug.cgi?id=31238 .

I pushed this patch which I this should address this issue.  Let me know
if you are still seeing failures.

Thanks,
Andrew

---

commit 98138c62cd7f721af132f9b24f274332fd8bf079
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Fri Jan 12 16:08:14 2024 +0000

    gdb/testsuite: fix failure in gdb.python/py-inferior.exp
    
    After this commit:
    
      commit 1925bba80edd37c2ef90ef1d2c599dfc2fc17f72
      Date:   Thu Jan 4 10:01:24 2024 +0000
    
          gdb/python: add gdb.InferiorThread.__repr__() method
    
    failures were reported for gdb.python/py-inferior.exp.
    
    The test grabs a gdb.InferiorThread object representing an inferior
    thread, and then, later in the test, expects this Python object to
    become invalid when the inferior thread has exited.
    
    The gdb.InferiorThread object was obtained from the list returned by
    calling gdb.Inferior.threads().
    
    The mistake I made in the original commit was to assume that the order
    of the threads returned from gdb.Inferior.threads() somehow reflected
    the thread creation order.  Specifically, I was expecting the main
    thread to be first in the list, and "other" threads to appear ... not
    first.
    
    However, the gdb.Inferior.threads() function creates a list and
    populates it from a map.  The order of the threads in the returned
    list has no obvious relationship to the thread creation order, and can
    vary from host to host.
    
    On my machine the ordering was as I expected, so the test passed for
    me.  For others the ordering was not as expected, and it just happened
    that we ended up recording the gdb.InferiorThread for the main thread.
    
    As the main thread doesn't exit (until the test is over), the
    gdb.InferiorThread object never became invalid, and the test failed.
    
    Fixed in this commit by taking more care to correctly find a non-main
    thread.  I do this by recording the main thread early on (when there
    is only one inferior thread), and then finding any thread that is not
    this main thread.
    
    Then, once all of the secondary threads have exited, I know that the
    second InferiorThread object I found should now be invalid.
    
    The test still passes for me, and I believe this should fix the issue
    for everyone else too.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31238

diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index 04231dd893d..2968e027812 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -94,27 +94,33 @@ gdb_test "python print(i0._user_attr)" \
 gdb_test "python print(gdb.inferiors()\[0\]._user_attr)" \
     "123" "read back user defined attribute from gdb.inferiors"
 
+# Record the main thread, and check its __repr__ while we're at it.
+gdb_test_no_output "python main_thread = gdb.inferiors()\[0\].threads()\[0\]"
+gdb_test "python print(main_thread)" \
+    "<gdb.InferiorThread id=${decimal}\\.${decimal} target-id=\"\[^\r\n\]*\">" \
+
 # Test the number of inferior threads.
 
 gdb_breakpoint check_threads
 gdb_continue_to_breakpoint "cont to check_threads" ".*pthread_barrier_wait.*"
 gdb_test "python print (len (i0.threads ()))" "\r\n9" "test Inferior.threads 2"
 
-# Grab the last thread from the list.  This thread object will become
-# invalid when the corresponding thread exits.
-gdb_test_no_output "python last_thread = i0.threads()\[-1\]"
-gdb_test "python print(last_thread)" \
+# Grab a worker thread from the thread list.  A worker thread is the
+# first thread that is not the main thread.  The worker thread object
+# will become invalid when the corresponding thread exits.
+gdb_test_no_output "python worker_thread = next(filter(lambda thr : thr != main_thread, i0.threads()))"
+gdb_test "python print(worker_thread)" \
     "<gdb.InferiorThread id=${decimal}\\.${decimal} target-id=\"\[^\r\n\]*\">" \
     "test repr of a valid thread"
 
-# Add a user defined attribute to this thread, check the attribute can
-# be read back, and check the attribute is not present on other
-# threads.
-gdb_test_no_output "python last_thread._user_attribute = 123" \
+# Add a user defined attribute to the worker thread, check the
+# attribute can be read back, and check the attribute is not present
+# on the main thread.
+gdb_test_no_output "python worker_thread._user_attribute = 123" \
     "add user defined attribute to InferiorThread object"
-gdb_test "python print(last_thread._user_attribute)" "123" \
+gdb_test "python print(worker_thread._user_attribute)" "123" \
     "read back user defined attribute"
-gdb_test "python print(i0.threads ()\[0\]._user_attribute)" \
+gdb_test "python print(main_thread._user_attribute)" \
     [multi_line \
 	 "AttributeError: 'gdb\\.InferiorThread' object has no attribute '_user_attribute'" \
 	 "Error while executing Python code\\."] \
@@ -126,12 +132,11 @@ gdb_breakpoint [gdb_get_line_number "Break here."]
 gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*"
 
 # Check the repr() for an invalid gdb.InferiorThread object.
-gdb_test "python print(last_thread)" \
-    "<gdb.InferiorThread \\(invalid\\)>" \
+gdb_test "python print(worker_thread)" "<gdb.InferiorThread \\(invalid\\)>" \
     "test repr of an invalid thread"
 
 # Check the user defined attribute is still present on the invalid thread object.
-gdb_test "python print(last_thread._user_attribute)" "123" \
+gdb_test "python print(worker_thread._user_attribute)" "123" \
     "check user defined attribute on an invalid InferiorThread object"
 
 # Test memory read and write operations.


      reply	other threads:[~2024-01-12 16:20 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-05 11:48 [PATCH 0/6] " Andrew Burgess
2024-01-05 11:48 ` [PATCH 1/6] gdb/python: hoist common invalid object repr code into py-utils.c Andrew Burgess
2024-01-09 19:19   ` Tom Tromey
2024-01-05 11:48 ` [PATCH 2/6] gdb/python: add gdb.InferiorThread.__repr__() method Andrew Burgess
2024-01-05 11:48 ` [PATCH 3/6] gdb/python: add gdb.Frame.__repr__() method Andrew Burgess
2024-01-05 11:48 ` [PATCH 4/6] gdb/python: remove users ability to create gdb.Progspace objects Andrew Burgess
2024-01-05 13:27   ` Eli Zaretskii
2024-01-05 11:48 ` [PATCH 5/6] gdb/python: Add gdb.Inferior.__dict__ attribute Andrew Burgess
2024-01-05 13:33   ` Eli Zaretskii
2024-01-09 20:05   ` Tom Tromey
2024-01-05 11:48 ` [PATCH 6/6] gdb/python: Add gdb.InferiorThread.__dict__ attribute Andrew Burgess
2024-01-05 13:31   ` Eli Zaretskii
2024-01-09 20:11   ` Tom Tromey
2024-01-10 10:38     ` Andrew Burgess
2024-01-10 15:54 ` [PATCHv2 0/8] Python __repr__() methods and new __dict__ attributes Andrew Burgess
2024-01-09 17:32   ` [PATCH] gdb/python: New InferiorThread.ptid_string attribute Andrew Burgess
2024-01-09 18:50     ` Eli Zaretskii
2024-01-09 19:10     ` Tom Tromey
2024-01-12  9:39       ` [PUSHED] " Andrew Burgess
2024-01-10 15:54     ` [PATCH] " Andrew Burgess
2024-01-10 15:54   ` [PATCHv2 1/8] gdb/python: hoist common invalid object repr code into py-utils.c Andrew Burgess
2024-01-10 15:54   ` [PATCHv2 2/8] gdb/python: add gdb.InferiorThread.__repr__() method Andrew Burgess
2024-01-10 15:54   ` [PATCHv2 3/8] gdb/python: add gdb.Frame.__repr__() method Andrew Burgess
2024-01-10 15:54   ` [PATCHv2 4/8] gdb/python: remove users ability to create gdb.Progspace objects Andrew Burgess
2024-01-10 15:54   ` [PATCHv2 5/8] gdb/python: Add gdb.Inferior.__dict__ attribute Andrew Burgess
2024-01-10 15:54   ` [PATCHv2 6/8] gdb/python: Add gdb.InferiorThread.__dict__ attribute Andrew Burgess
2024-01-10 15:54   ` [PATCHv2 7/8] gdb/doc: add some notes on selecting suitable attribute names Andrew Burgess
2024-01-10 16:35     ` Eli Zaretskii
2024-01-11 10:48       ` Andrew Burgess
2024-01-11 10:56         ` Eli Zaretskii
2024-01-10 15:54   ` [PATCHv2 8/8] gdb/doc: update examples in gdb.Progspace and gdb.Objfile docs Andrew Burgess
2024-01-10 16:36     ` Eli Zaretskii
2024-01-10 18:08   ` [PATCHv2 0/8] Python __repr__() methods and new __dict__ attributes Tom Tromey
2024-01-12 13:44     ` Andrew Burgess
2024-01-12 14:57       ` Tom de Vries
2024-01-12 16:20         ` Andrew Burgess [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h6ji7cby.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).