From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 33296394800A for ; Mon, 19 Apr 2021 09:05:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 33296394800A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-TnbTiHkFNtibTv9X__4oIA-1; Mon, 19 Apr 2021 05:05:55 -0400 X-MC-Unique: TnbTiHkFNtibTv9X__4oIA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6BE4E107ACC7; Mon, 19 Apr 2021 09:05:54 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E5FF5D741; Mon, 19 Apr 2021 09:05:52 +0000 (UTC) From: Florian Weimer To: Pedro Alves Cc: Simon Marchi , libc-alpha@sourceware.org, gdb-patches@sourceware.org, Emil Velikov , Kevin Buettner Subject: Re: [PATCH glibc] nptl_db: different libpthread/ld.so load orders (bug 27744) References: <87sg3qnrz3.fsf@oldenburg.str.redhat.com> <73b32cc6-e201-8bac-e442-e3dddcc01e0d@polymtl.ca> <625ec5fe-bd09-860a-f617-745042b94011@redhat.com> <87fszqnqi3.fsf@oldenburg.str.redhat.com> <87blaenprw.fsf@oldenburg.str.redhat.com> <87tuo6m957.fsf@oldenburg.str.redhat.com> <8285fcc7-aabd-48db-d256-1531e7b6f11b@palves.net> Date: Mon, 19 Apr 2021 11:06:04 +0200 In-Reply-To: <8285fcc7-aabd-48db-d256-1531e7b6f11b@palves.net> (Pedro Alves's message of "Fri, 16 Apr 2021 18:43:53 +0100") Message-ID: <87eef663ur.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Apr 2021 09:06:09 -0000 --=-=-= Content-Type: text/plain * Pedro Alves: > Even without reducing, it is possible to make the program that triggers the > assertion be a standalone program? git clone https://pagure.io/glibc/glibc-support cd glibc-support make Then drop the attached file into the tests subdirectory, and run: make LDFLAGS=-lpthread build/tst-pthread-gdb-attach This should reproduce the issue out side of the glibc tree. > Any reason you're using "add-symbol-file" in the first place, instead > of "file"? The main program is ld.so. Thanks, Florian --=-=-= Content-Type: text/plain Content-Disposition: attach; filename=tst-pthread-gdb-attach.c /* Smoke testing GDB process attach with thread-local variable access. Copyright (C) 2021 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see . */ /* This test runs GDB against a forked copy of itself, to check whether libthread_db can be loaded, and that access to thread-local variables works. */ #include #include #include #include #include #include #include #include #include #include /* Starts out as zero, changed to 1 or 2 by the debugger, depending on the thread. */ __thread volatile int altered_by_debugger; /* Writes the GDB script to run the test to PATH. */ static void write_gdbscript (const char *path, int tested_pid) { FILE *fp = xfopen (path, "w"); char *exepath = realpath ("/proc/self/exe", NULL); TEST_VERIFY_EXIT (exepath != NULL); fprintf (fp, "set trace-commands on\n" "set debug libthread-db 1\n" "add-symbol-file %s\n" "attach %d\n", exepath, tested_pid); fputs ("break debugger_inspection_point\n" "continue\n" "thread 1\n" "print altered_by_debugger\n" "print altered_by_debugger = 1\n" "thread 2\n" "print altered_by_debugger\n" "print altered_by_debugger = 2\n" "continue\n", fp); free (exepath); xfclose (fp); } /* The test sets a breakpoint on this function and alters the altered_by_debugger thread-local variable. */ void __attribute__ ((weak)) debugger_inspection_point (void) { } /* Thread function for the test thread in the subprocess. */ static void * subprocess_thread (void *closure) { /* Wait until altered_by_debugger changes the value away from 0. */ while (altered_by_debugger == 0) { usleep (100 * 1000); debugger_inspection_point (); } TEST_COMPARE (altered_by_debugger, 2); return NULL; } /* This function implements the subprocess under test. It creates a second thread, waiting for its value to change to 2, and checks that the main thread also changed its value to 1. */ static void in_subprocess (void) { pthread_t thr = xpthread_create (NULL, subprocess_thread, NULL); TEST_VERIFY (xpthread_join (thr) == NULL); TEST_COMPARE (altered_by_debugger, 1); _exit (0); } static int do_test (void) { pid_t tested_pid = xfork (); if (tested_pid == 0) in_subprocess (); char *tested_pid_string = xasprintf ("%d", tested_pid); char *gdbscript; xclose (create_temp_file ("tst-pthread-gdb-attach-", &gdbscript)); write_gdbscript (gdbscript, tested_pid); pid_t gdb_pid = xfork (); if (gdb_pid == 0) { clearenv (); xdup2 (STDOUT_FILENO, STDERR_FILENO); execlp ("gdb", "gdb", "-nx", "-batch", "-x", gdbscript, NULL); if (errno == ENOENT) _exit (EXIT_UNSUPPORTED); else _exit (1); } int status; TEST_COMPARE (xwaitpid (gdb_pid, &status, 0), gdb_pid); if (WIFEXITED (status) && WEXITSTATUS (status) == EXIT_UNSUPPORTED) /* gdb is not installed. */ return EXIT_UNSUPPORTED; TEST_COMPARE (status, 0); TEST_COMPARE (xwaitpid (tested_pid, &status, 0), tested_pid); TEST_COMPARE (status, 0); free (tested_pid_string); free (gdbscript); return 0; } #include --=-=-=--