aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2024-01-12 16:08:14 +0000
committerAndrew Burgess <aburgess@redhat.com>2024-01-12 16:08:14 +0000
commit98138c62cd7f721af132f9b24f274332fd8bf079 (patch)
treeb2cd51f6928dcc36e4ae7db0774d241e69618bcc /gdb
parent1d506c26d9772bcd84e1a7b3a8c8c5bc602dbf61 (diff)
downloadfsf-binutils-gdb-98138c62cd7f721af132f9b24f274332fd8bf079.zip
fsf-binutils-gdb-98138c62cd7f721af132f9b24f274332fd8bf079.tar.gz
fsf-binutils-gdb-98138c62cd7f721af132f9b24f274332fd8bf079.tar.bz2
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
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.python/py-inferior.exp31
1 files changed, 18 insertions, 13 deletions
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index 04231dd..2968e02 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.