From patchwork Tue Mar 27 16:23:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Bunt X-Patchwork-Id: 26493 Received: (qmail 10425 invoked by alias); 27 Mar 2018 16:24:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5915 invoked by uid 89); 27 Mar 2018 16:24:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=Switching X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0074.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Mar 2018 16:24:02 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Richard.Bunt@arm.com; Received: from e112476-lin.warwick.arm.com (217.140.96.140) by VI1PR0801MB1646.eurprd08.prod.outlook.com (2603:10a6:800:59::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.609.10; Tue, 27 Mar 2018 16:23:59 +0000 From: Richard Bunt To: gdb-patches@sourceware.org Cc: nd@arm.com, Richard Bunt Subject: [PATCH] Add test case for a known hang in infrun Date: Tue, 27 Mar 2018 17:23:48 +0100 Message-Id: <1522167828-17287-1-git-send-email-richard.bunt@arm.com> MIME-Version: 1.0 X-ClientProxiedBy: LO2P265CA0042.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::30) To VI1PR0801MB1646.eurprd08.prod.outlook.com (2603:10a6:800:59::13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 18368e17-354d-4eff-86f5-08d593ff2546 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0801MB1646; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1646; 3:nHRGQYnlh2aMwU/5JTxVxN1k9b4EAfsNic7twKNmRSXJ/TCB94s2fh3XHSAJFPLaL2q3L80W2HU3aG4YVptVSvbLcTlbq9kZy69tlwPecwiJEom4+ME5QGY0HNmv5knUAyUmIxaEoALn+LuToxJSfg9Ilug1thc8Z78L4Orwy7gY9ZSVWPEuRBrFWoFgzh60N82++Ig6l3ilUUZIaHrORA0v8LVOgIvVY7YkKP472pV4ZJEjyPNtgJ2uAv3cOwDP; 25:i7DyERFU13rzZzOWzQUhCMA6y42s8hoLZHiHMdtW1Te7WRavEYq5Ihi0/jUfVke8pDwnJ+IOcmRiTWq+MwnbuZTgqNDTgOtOpQasVQcuf6xOEpIAG/tdL1ehGHV4u11eowBuo8DPM4WVKfwrrbBaImrl/XYDao4INZWGHBSfw1JHOcJzpnlA/syQwbczLnlY++o+IefN/FG3sp2b3KmbsduG0QXFsCvpne6a/tkk4GIPrTB3m+9t84hOLgzmAk5LHdMzx0qQIjbva4GDswKlx/5Ye1PAkm2jPk6Bu3D7/dJiGwd3Na5/DESgwMndDjvQhMVpyYqwyNAszZezDHCn/A==; 31:KIggHMTgCzR67EFLKCLt1ax4Ng+R26YEW5mG30P0jV3gcPBFWCRhMQQ+5gZKoRuG1KjhvFtnaCz6YUI/Ei3r2v+j9E8q+7c3xfgMwESoIJMyDBZnQFDBPbqX2GA4+fADC72L+ESZxmz+wcaofKPhWVmSw12TRX8cyoxi9QZOW9lZObd+gHAc052amDbmuQCBluXF1lJB3AAtUIVQ0T9azlzYqUxiLsNDU/OGr32ggBU= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1646: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1646; 20:LctqHSGfwsBVS42AHSFrMOvylA/EguEFZn4By9Eoe2wdDAx8JpKYwFUIsJZd7TmDOxl+seBTydgVuwGjhj/LdCc9dXcd79RJywKdWi1egcez0wCUcetVMtBTkqinXsu3mjRCioUt0sN+/vjamvqCjUIRIxuY+Wpam4W9N3NeZ7E=; 4:IQHhoUy9uqUHyPsyHdSoa6MvZwhTH0AyymOlkvzUmrjkBqrl+2m/ieuaZmBPBTEsYXItfr/d3nW2v6QOCzn7BZ4wWWC1KEnbHfJHhI6cg1QNpj2HUgINzfv3nG5kwdlodQucA2Uvbj9UV03dvP5F/bopImxOc3TeuEvzhmYiuV0SBlGQ2co77xl87HHvfN6aejKpKraK9pMvDOzubFzjm+pLIR8botFz6GT3S0wNsW2WWkahNqlJH/CuTR8bxMWuraoRVI3HKudWwT7SWhAJpSlFxeEHRtzvfXwQTEBdO1LMRJc/bshwfSlU7r2W6RWB90WHBGvR/Gy6XYd6W4Q+2P3pVSnSsTuYaMHQQJQ7iIk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(22074186197030); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231221)(944501327)(52105095)(6055026)(6041310)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:VI1PR0801MB1646; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1646; X-Forefront-PRVS: 0624A2429E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39380400002)(366004)(39860400002)(396003)(376002)(199004)(189003)(54534003)(51416003)(7736002)(86362001)(4326008)(59450400001)(48376002)(106356001)(105586002)(7696005)(2361001)(386003)(2351001)(486005)(2906002)(476003)(305945005)(486005)(956004)(50466002)(1857600001)(97736004)(6306002)(2616005)(52116002)(6486002)(8936002)(478600001)(53936002)(72206003)(316002)(81156014)(26005)(66066001)(16526019)(68736007)(3846002)(6116002)(186003)(8676002)(6666003)(36756003)(81166006)(16586007)(6916009)(25786009)(50226002)(5660300001)(47776003)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0801MB1646; H:e112476-lin.warwick.arm.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1646; 23:EfiUdQWN8AKcb/9phHujXrz1WKh/iLFyuSpKTrN?= =?us-ascii?Q?dLmJXYp3GCmuHsoOCDfo8oL46itX9JUHwZbWjIoQDjXYMlhtjjKNJpwyhZp6?= =?us-ascii?Q?SP3LcyaM+flFZgtoTuQ09tBmQIGq8KGDyglT7A25amoPma+CQ1LXaAK1LyPZ?= =?us-ascii?Q?laH9ax3BBc0dAYrBzsb/avWvw4h9FJhVkWhJ9M6f/kVtljHwe2o+spmlUFm5?= =?us-ascii?Q?kcaAg/8Ok8wEXWw0dL9aac0Z9Z4IrPhPGbuOg9weFLTSdUY417h3jazsHiYv?= =?us-ascii?Q?ApO6QQzruABRsS2dPVLfZO3q+LIKikMB8miCLjKAsf0Hd2fhOIjPdkTL1IQs?= =?us-ascii?Q?RRed+9dDe6GPP9CD9FfYdNb81ixvseX/mytzgkwc1vZ+ANkR4snDCkw/o5vU?= =?us-ascii?Q?8ZQtCiahZe1mw6OWDIYyscsy7A2lyvhxDr0MEIRdD9dFaiZdmqj2KRrBv3BT?= =?us-ascii?Q?icrAUUHg/ScczL3kTdUVxdNlFt2pZPGRAVe+lGaeDhprC1T7InGBAAhuwqKj?= =?us-ascii?Q?jMIthPY7221Xcd44VpkClC+9oU5aYxAbG7jjjce+7Ksws5hWIJPeIexBg7xe?= =?us-ascii?Q?rsWmT7KNV4Y5LDDR+X0r6VLZWTv2BPi0gdoYuSZ74I/Pq1ZzIysYKDEJfTsZ?= =?us-ascii?Q?XJGtDJvDErVbZ5Cmnr3P4/23YbLnfM+diMFar3gDP+goQwXO/HUYKdma8TEX?= =?us-ascii?Q?h7LbZUtGML6fKZZNxVekWlha1aWlyuugcRPG8GUetN7/o+qF18wp5MjcP22c?= =?us-ascii?Q?m7qWvqunA2nOyVq22pfMJ5PBGYyEAxUZmZJDZRQChQeb74P4zFznT0p8G6xA?= =?us-ascii?Q?a5v5t9P7wN3xgb4dz4QL1a1m3hQ+XRtqRXhssRvKdqCBGtkRLE1bEajKZoXU?= =?us-ascii?Q?9rLTLEmce4FUmIpltiYmW0J5GXDknq8bDsa5AgSpJpaeS+2ACWLK7u5fKhR2?= =?us-ascii?Q?8JXoiG56iiWZzTVBvgAOHhlqH821oEZswPqjLgEhyNPt5tzsZWqNa8hxXfSC?= =?us-ascii?Q?A7XekBuT3cZGtRrma1nzRE4mDWNRNtkfInWIQI9VeX9n0KDZqmnbLop5wZwT?= =?us-ascii?Q?dwMSKovinC34vvEzw64SUNmsJ/8kIqTngU+ZF4QCLt11nWet5a+8e71txXdD?= =?us-ascii?Q?8amIiZDUIbXQ9sJhGtYER9rus2EY72WGEdcSJVtlsrasQGYkWpsoJMJ2M+T7?= =?us-ascii?Q?RgHSz+Ws4ktxwlBxJfOgQAw3VV1YbXvXhNa2DFxKvw6fyRyI4K9rUfa3t3Jq?= =?us-ascii?Q?1q0qtu4uYCu2uwXQH7N3wRglvLnLkoQvyRmfRe3vRXRXLiuY22QKngjMCImp?= =?us-ascii?Q?tmA=3D=3D?= X-Microsoft-Antispam-Message-Info: gMFQvvTvGOxNcfxK7c7DeGYj7+HU3N1jT1+8YgGjzF7FrRaB7xz7ycOG4Z6Eb8N5FPjNCCR33R41k24fbvGRwIVUohVM47S+8UTQXFG1xTxRZMMjNrTd4J4RPiZaBIM5qluMr3rSUArr0a9tU6nZ9t3/wJ8Zg4f6GDL8+p9u7ePEDyLyRvQH4QUCIszgklAZ X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1646; 6:ILoOBf0B67ZA8okgpua7v8eRNokkpN+8/0rK0D74SMRxEDXqEKu4Scs40oVR/OYGJGEH+FhWMkbQaoroGuccq7HR7FWmlIDSM5gqt5M2lvRLmasxJ0wdYiQoxMwifNqN5iPFUaA6BVatsfW9qv6/dQhGGtyNrI6LkC2fa5XhCn1EQF3RF0cXHQgUJb+o9q0S1v6mz4DFUn6Spc/KEddBwMXaU8fVaXA5N2T47v71V26arazR7VExVL2tImVesz+nTP1Uiw1OO+rLLvOrNa5eJxiRcyoMMK95LjXD15YdwiPScB8KU6GrIr5026xNU4OGv8YRLvw912dAcwL+XwHo57mrGCRr4rmSUQoqqzt4U1/eDrtS1LDjfBbKUdFdG7FeBaMnJUj1cZy9iScOXA3dMGKcS96BQMH/RfCSqFLFLlkKA/MhI9Pdoo0nIaSfjBfxantxL31Mm4pTCrOmzTL9Xw==; 5:/4FBAVoGojOlL1KaBYRnvzKXzBJUCmHvXaXzW2NY/SoOxOI9sd//ju6ujnD/psKiEGW4JVeddfRyI7Oi658E+UamkhHQfMptOFWK+p7T5NFNtnfC6hiDw0ivYD+B2vouRouDGqLw3YhPozx2gAuL93kQxuYTnuwH+LkYFRX5pqs=; 24:HSdTOZkQZUxx4pCH2ZL2NqWdcobcrZH5wXjr2GObtWJuAsN6sh3HjzFvl9npSjnleBpxk+jk6VLwiLUI6dUdLkBeBTAwwDuhzhJQDlhURM4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1646; 7:k5bnyvRAGGa0Zt29j/HoksrTU1FeDB0jNuFSWD5HTEr9VMhi1ItPMkN96qHP7DhzQOKDHtcTX9tjfnRi719zpxy1FW1LVMcZT970WKoSu7yxYUb6DBrXbEaFykdaKx6V1ZFwpUxnFWb62RJsUafnvmbd1dqMuzKXIF4vqOqJnCDgR2oa9f1AyvjqovTMBVN6eiC+Wvx2eXbUMakW+v9T9p//2HrZqsK/ZZJBjGvKeA0dz3Lmb7Mi4aKrrHrfRZ8X X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2018 16:23:59.1615 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 18368e17-354d-4eff-86f5-08d593ff2546 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1646 X-IsSubscribed: yes The hang occurs when GDB tries to call inferior functions on two different threads with scheduler-locking turned on. The first call works fine, with the call to infrun_async(1) causing the signal_handler to be marked and the event to be handled, but then the event loop resets the "ready" member to zero, while leaving infrun_is_async set to 1. As a result, GDB hangs if the user switches to another thread and calls a second function because calling infrun_async(1) a second time has no effect, meaning the inferior call events are never handled. The added test case provokes the above issue. gdb/testsuite/ChangeLog: * gdb.threads/multiple-successive-infcall.c: New test. * gdb.threads/multiple-successive-infcall.exp: New file. --- .../gdb.threads/multiple-successive-infcall.c | 104 +++++++++++++++++++++ .../gdb.threads/multiple-successive-infcall.exp | 55 +++++++++++ 2 files changed, 159 insertions(+) create mode 100644 gdb/testsuite/gdb.threads/multiple-successive-infcall.c create mode 100644 gdb/testsuite/gdb.threads/multiple-successive-infcall.exp diff --git a/gdb/testsuite/gdb.threads/multiple-successive-infcall.c b/gdb/testsuite/gdb.threads/multiple-successive-infcall.c new file mode 100644 index 0000000..3010c18 --- /dev/null +++ b/gdb/testsuite/gdb.threads/multiple-successive-infcall.c @@ -0,0 +1,104 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2018 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include +#include + +/* This defines the number of threads to spawn. */ +#define THREADCOUNT 4 + +/* Global barrier type to control synchronization between threads. */ +pthread_barrier_t print_barrier; +/* Define global thread identifiers. */ +pthread_t threads[THREADCOUNT]; +/* Memory for threads to read from when get_value is called by the + debugger. */ +int thread_ids[THREADCOUNT]; + +/* Return the argument back, within range [0..THREADCOUNT). + This is the function called on the inferiors from the debugger. */ +int +get_value (int index) +{ + return thread_ids[index]; +} + +/* Return the nth Fibonacci number. */ +unsigned long +fast_fib (unsigned int n) +{ + int a = 0; + int b = 1; + int t; + for (unsigned int i = 0; i < n; ++i) + { + t = b; + b = a + b; + a = t; + } + return a; +} + +/* Encapsulate the synchronization of the threads. Perform a barrier before + and after the computation. */ +void * +thread_function (void *args) +{ + int tid = get_value (*((int *) args)); + int status = pthread_barrier_wait (&print_barrier); + if (status == PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("All threads entering compute region\n"); + } + unsigned long result = fast_fib (100); // testmarker01 + status = pthread_barrier_wait (&print_barrier); + if (status == PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("All threads outputting results\n"); + } + pthread_barrier_wait (&print_barrier); + printf ("Thread %d Result: %lu\n", tid, result); + pthread_exit (NULL); +} + +int +main (void) +{ + int err = pthread_barrier_init (&print_barrier, NULL, THREADCOUNT); + // Create the worker threads (main). + printf ("Spawning worker threads\n"); + for (int tid = 0; tid < THREADCOUNT; ++tid) + { + thread_ids[tid] = tid; + err = + pthread_create (&threads[tid], NULL, thread_function, + (void *) &thread_ids[tid]); + if (err) + { + fprintf (stderr, "Thread creation failed\n"); + return EXIT_FAILURE; + } + } + // Wait for the threads to complete then exit. + for (int tid = 0; tid < THREADCOUNT; ++tid) + { + pthread_join (threads[tid], NULL); + } + pthread_exit (NULL); + return EXIT_SUCCESS; +} diff --git a/gdb/testsuite/gdb.threads/multiple-successive-infcall.exp b/gdb/testsuite/gdb.threads/multiple-successive-infcall.exp new file mode 100644 index 0000000..363f8e0 --- /dev/null +++ b/gdb/testsuite/gdb.threads/multiple-successive-infcall.exp @@ -0,0 +1,55 @@ +# Copyright (C) 2018 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# multiple-successive-infcall.exp -- Test if GDB can invoke functions on +# multiple inferiors, one after the other. + +standard_testfile + +if [get_compiler_info] { + return -1 +} + +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ + executable {debug}] != "" } { + return -1 +} + +clean_restart "${binfile}" + +if ![runto_main] then { + fail "Can't run to main" + return 0 +} + +gdb_breakpoint [gdb_get_line_number "testmarker01"] +gdb_continue_to_breakpoint "testmarker01" +gdb_test_no_output "set scheduler-locking on" +gdb_test "show scheduler-locking" \ + "Mode for locking scheduler during execution is \"on\"." + +foreach thread {4 3 2 1} { + gdb_test "thread ${thread}" "Switching to .*" + set command "call get_value(0)" + gdb_test_multiple "${command}" "${command}" { + -re ".*\[\r\n]+${gdb_prompt} $" { + pass "Call on inferior returned successfully." + } + timeout { + kfail "gdb/22882" "Call on inferior hung." + return 0 + } + } +}