From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2607 invoked by alias); 5 Jun 2014 07:17:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 2596 invoked by uid 89); 5 Jun 2014 07:17:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Jun 2014 07:17:08 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1WsRv6-0000oo-Ph from Yao_Qi@mentor.com ; Thu, 05 Jun 2014 00:17:04 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 5 Jun 2014 00:17:04 -0700 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.2.247.3; Thu, 5 Jun 2014 00:16:15 -0700 Message-ID: <539018F9.5060307@codesourcery.com> Date: Thu, 05 Jun 2014 07:17:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Jan Kratochvil , Subject: Re: [patch] Fix TLS access for -static -pthread References: <20140410115204.GB16411@host2.jankratochvil.net> In-Reply-To: <20140410115204.GB16411@host2.jankratochvil.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2014-06/txt/msg00233.txt.bz2 On 04/10/2014 07:52 PM, Jan Kratochvil wrote: > +if { "$have_tls" != "" } { > + if ![runto_main] { > + return -1 > + } > + gdb_breakpoint [gdb_get_line_number "tlsvar-is-set"] > + gdb_continue_to_breakpoint "tlsvar-is-set" ".* tlsvar-is-set .*" > + gdb_test "p tlsvar" " = 2" "tlsvar in thread" > + gdb_test "thread 1" ".*" > + # Unwind from pthread_join. > + gdb_test "up 10" " in main .*" This is racy. When child thread hits breakpoint, the main thread may not go into pthread_join yet and may not be unwind to main. On target arm-none-linux-gnueabi, I see thread 1^M [Switching to thread 1 (Thread 5784)]^M #0 clone () at ../ports/sysdeps/unix/sysv/linux/arm/nptl/../clone.S:62^M 62 cmp r0, #0^M (gdb) PASS: gdb.threads/staticthreads.exp: thread 1 up 10^M #2 0xbe8ea7e4 in ?? ()^M (gdb) FAIL: gdb.threads/staticthreads.exp: up 10 p tlsvar^M $2 = 1^M (gdb) PASS: gdb.threads/staticthreads.exp: tlsvar in main This patch is to set another breakpoint at the end of main, so that main thread will hit it, and we can check the value of tlsvar then. It is safe and we don't have to worry about whether gdb is able to unwind from pthread library to main function or not. Is it good to you? b.t.w, this case is UNSUPPORTED on FC 20, because staticthreads.c can't be compiled. I guess this case requires some recent version of glibc. -- Yao (齐尧) Subject: [PATCH] Fix the race in gdb.threads/staticthreads.exp The code in gdb.threads/staticthreads.exp about checking the value of tlsvar in main thread is racy, because when child thread hits breakpoint, the main thread may not go into pthread_join yet, and may not be unwind to main. This patch is to set another breakpoint at the end of main, so that main thread will hit it, and we can check the value of tlsvar then. gdb/testsuite: 2014-06-05 Yao Qi * gdb.threads/staticthreads.c (main): Add one line of comment as a marker to set breakpoint. * gdb.threads/staticthreads.exp: Don't unwind in main thread. Instead, set breakpoint on the marker and continue the main thread. --- gdb/testsuite/gdb.threads/staticthreads.c | 2 +- gdb/testsuite/gdb.threads/staticthreads.exp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/gdb.threads/staticthreads.c b/gdb/testsuite/gdb.threads/staticthreads.c index 5c8eabe..a11359c 100644 --- a/gdb/testsuite/gdb.threads/staticthreads.c +++ b/gdb/testsuite/gdb.threads/staticthreads.c @@ -76,6 +76,6 @@ main (int argc, char **argv) pthread_join (thread, NULL); } - pthread_attr_destroy (&attr); + pthread_attr_destroy (&attr); /* tlsvar-is-read */ return 0; } diff --git a/gdb/testsuite/gdb.threads/staticthreads.exp b/gdb/testsuite/gdb.threads/staticthreads.exp index 9fa625a..3e23b5b 100644 --- a/gdb/testsuite/gdb.threads/staticthreads.exp +++ b/gdb/testsuite/gdb.threads/staticthreads.exp @@ -104,8 +104,9 @@ if { "$have_tls" != "" } { gdb_breakpoint [gdb_get_line_number "tlsvar-is-set"] gdb_continue_to_breakpoint "tlsvar-is-set" ".* tlsvar-is-set .*" gdb_test "p tlsvar" " = 2" "tlsvar in thread" + gdb_test "thread 1" ".*" - # Unwind from pthread_join. - gdb_test "up 10" " in main .*" + gdb_breakpoint ${srcfile}:[gdb_get_line_number "tlsvar-is-read"] + gdb_continue_to_breakpoint "tlsvar-is-read" ".* tlsvar-is-read .*" gdb_test "p tlsvar" " = 1" "tlsvar in main" } -- 1.9.0