public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/testsuite] Fix check-libthread-db.exp FAILs with glibc 2.33
@ 2021-07-07 14:09 Tom de Vries
  2021-07-13  4:49 ` Simon Marchi
  0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2021-07-07 14:09 UTC (permalink / raw)
  To: gdb-patches

Hi,

When running test-case gdb.threads/check-libthread-db.exp on openSUSE
Tumbleweed with glibc 2.33, I get:
...
(gdb) maint check libthread-db^M
Running libthread_db integrity checks:^M
  Got thread 0x7ffff7c79b80 => 9354 => 0x7ffff7c79b80; errno = 0 ... OK^M
libthread_db integrity checks passed.^M
(gdb) FAIL: gdb.threads/check-libthread-db.exp: user-initiated check: libpthread.so not initialized (pattern 2)
...

The test-case expects instead:
...
  Got thread 0x0 => 9354 => 0x0 ... OK^M
...
which is what I get on openSUSE Leap 15.2 with glibc 2.26, and what is
described in the test-case like this:
...
    # libthread_db should fake a single thread with th_unique == NULL.
...

Using a breakpoint on check_thread_db_callback we can compare the two
scenarios, and find that in the latter case we hit this code in glibc function
iterate_thread_list in nptl_db/td_ta_thr_iter.c:
...
  if (next == 0 && fake_empty)
    {
      /* __pthread_initialize_minimal has not run.  There is just the main
         thread to return.  We cannot rely on its thread register.  They
         sometimes contain garbage that would confuse us, left by the
         kernel at exec.  So if it looks like initialization is incomplete,
         we only fake a special descriptor for the initial thread.  */
      td_thrhandle_t th = { ta, 0 };
      return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
    }
...
while in the former case we don't because this preceding statement doesn't
result in next == 0:
...
  err = DB_GET_FIELD (next, ta, head, list_t, next, 0);
...

Note that the comment mentions __pthread_initialize_minimal, but in both cases
it has already run before we hit the callback, so it's possible the comment is
no longer accurate.

Anyway, the results do not look wrong, so fix this by updating the regexp
patterns to agree with what libthread-db is telling us.

Tested on x86_64-linux, both with glibc 2.33 and 2.26.

Any comments?

Thanks,
- Tom

[gdb/testsuite] Fix check-libthread-db.exp FAILs with glibc 2.33

gdb/testsuite/ChangeLog:

2021-07-07  Tom de Vries  <tdevries@suse.de>

	PR testsuite/27690
	* gdb.threads/check-libthread-db.exp: Update patterns for glibc 2.33.

---
 gdb/testsuite/gdb.threads/check-libthread-db.exp | 37 ++++++++++++++----------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/check-libthread-db.exp b/gdb/testsuite/gdb.threads/check-libthread-db.exp
index dfb3bad3712..6ecf40db6a9 100644
--- a/gdb/testsuite/gdb.threads/check-libthread-db.exp
+++ b/gdb/testsuite/gdb.threads/check-libthread-db.exp
@@ -32,6 +32,13 @@ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
     return -1
 }
 
+# Case 1: libthread_db fakes a single thread with th_unique == NULL.
+set thread_re1 "0 => $decimal => 0"
+# Case 2: libthread_db already initialized.
+set thread_re2 "$hex => $decimal => ${hex}(; errno = 0)?"
+# Match either of the two cases.
+set initial_thread_re "($thread_re1|$thread_re2)"
+
 with_test_prefix "user-initiated check" {
 
     # User-initiated check with libthread_db not loaded.
@@ -49,18 +56,16 @@ with_test_prefix "user-initiated check" {
 	"No libthread_db loaded" \
 	"no libpthread.so loaded"
 
-
-    # User-initiated check with NPTL uninitialized.
-    # libthread_db should fake a single thread with th_unique == NULL.
+    # User-initiated check with NPTL possibly uninitialized.
     gdb_test "continue" \
 	".*Stopped due to shared library event.*Inferior loaded .*libpthread.*"
 
     gdb_test_sequence "maint check libthread-db" \
-	"libpthread.so not initialized" {
-	    "\[\r\n\]+Running libthread_db integrity checks:"
-	    "\[\r\n\]+\[ \]+Got thread 0x0 => \[0-9\]+ => 0x0 ... OK"
-	    "\[\r\n\]+libthread_db integrity checks passed."
-	}
+	"libpthread.so possibly not initialized" \
+	[list \
+	     "\[\r\n\]+Running libthread_db integrity checks:" \
+	     "\[\r\n\]+\[ \]+Got thread $initial_thread_re ... OK" \
+	     "\[\r\n\]+libthread_db integrity checks passed."]
 
     # User-initiated check with NPTL fully operational.
     gdb_test_no_output "set stop-on-solib-events 0"
@@ -78,8 +83,8 @@ with_test_prefix "user-initiated check" {
 
 with_test_prefix "automated load-time check" {
 
-    # Automated load-time check with NPTL uninitialized.
-    with_test_prefix "libpthread.so not initialized" {
+    # Automated load-time check with NPTL possibly uninitialized.
+    with_test_prefix "libpthread.so possibly not initialized" {
 	clean_restart ${binfile}
 
 	gdb_test_no_output "maint set check-libthread-db 1"
@@ -88,12 +93,12 @@ with_test_prefix "automated load-time check" {
 	gdb_run_cmd
 
 	gdb_test_sequence "" \
-	    "check debug libthread-db output" {
-		"\[\r\n\]+Running libthread_db integrity checks:"
-		"\[\r\n\]+\[ \]+Got thread 0x0 => \[0-9\]+ => 0x0 ... OK"
-		"\[\r\n\]+libthread_db integrity checks passed."
-		"\[\r\n\]+[Thread debugging using libthread_db enabled]"
-	    }
+	    "check debug libthread-db output" \
+	    [list \
+		 "\[\r\n\]+Running libthread_db integrity checks:" \
+		 "\[\r\n\]+\[ \]+Got thread $initial_thread_re ... OK" \
+		 "\[\r\n\]+libthread_db integrity checks passed." \
+		 "\[\r\n\]+\\\[Thread debugging using libthread_db enabled\\\]"]
     }
 
     # Automated load-time check with NPTL fully operational.

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

end of thread, other threads:[~2021-07-13 13:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-07 14:09 [PATCH][gdb/testsuite] Fix check-libthread-db.exp FAILs with glibc 2.33 Tom de Vries
2021-07-13  4:49 ` Simon Marchi
2021-07-13 12:59   ` Tom de Vries
2021-07-13 13:15     ` Tom de Vries
2021-07-13 13:31       ` Simon Marchi

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