From patchwork Wed Sep 20 17:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 76461 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E45B5385C6D4 for ; Wed, 20 Sep 2023 18:00:41 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by sourceware.org (Postfix) with ESMTPS id 52A273857731 for ; Wed, 20 Sep 2023 18:00:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52A273857731 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40472f9db24so892745e9.2 for ; Wed, 20 Sep 2023 11:00:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695232823; x=1695837623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SnpUVwB06Gqt5taMmSzeAdKZrCa+mHLDAyKyAWOedbE=; b=OYN2nynStNg0CjeooEmIK33q4W+M1hPFlLR+VMYyf+oN6w3t1xMEVrONz2Pikzo59m piE2aN4jPpl6Ez9NSD+k5nJHiiQINn/cGgl2aOatbELQZnCEit0lV/w9LYoKachOKb42 ndD7PSTDTMSFls3PcuNHwuyAZWKIlBH7P28UiTbjldyaZjVayn4weGhvPkxXebt6PdhE 6TXc8AoOWLwhfpFzQcEiri5ADY7B2qQV8PR8p2vNYLdibvKeWIQCDilT8jiXePJ5rxcB uBbJiVWZyBztBENXbQ6ryrmXIPNYsyNFDiJrEdyiC5HP+46j3EkJH1pH7U3HTtrBGN19 zQvg== X-Gm-Message-State: AOJu0Yw64ECuijGD+7ELBen1OTHjzdxUfy4uahptdc+K+ojwTnhnZemV OQU+4Szdl+p1H87Dj7+eEafPY/rUcVpZXg== X-Google-Smtp-Source: AGHT+IHvk94J8as7caw3txUVfM+laSAryoc0Q9bgwHFnCX549/vgpRQnOHhj9wXw5a7xxTeqnx0fNQ== X-Received: by 2002:a7b:cb02:0:b0:401:c0ef:c287 with SMTP id u2-20020a7bcb02000000b00401c0efc287mr3209563wmj.27.1695232822668; Wed, 20 Sep 2023 11:00:22 -0700 (PDT) Received: from localhost ([2001:8a0:f939:d200:f66d:9e3b:9c38:4aec]) by smtp.gmail.com with UTF8SMTPSA id 15-20020a05600c020f00b00401d8810c8bsm2582636wmi.15.2023.09.20.11.00.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Sep 2023 11:00:21 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 3/5] Fix gdb.threads/pthreads.exp error handling/printing Date: Wed, 20 Sep 2023 18:59:57 +0100 Message-Id: <20230920175959.2305271-4-pedro@palves.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920175959.2305271-1-pedro@palves.net> References: <20230920175959.2305271-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" On Cygwin, I noticed: (gdb) PASS: gdb.threads/pthreads.exp: break thread1 continue Continuing. pthread_attr_setscope 1: No error [Thread 8732.0x28f8 exited with code 1] [Thread 8732.0xb50 exited with code 1] [Thread 8732.0x17f8 exited with code 1] Program terminated with signal SIGHUP, Hangup. The program no longer exists. (gdb) FAIL: gdb.threads/pthreads.exp: Continue to creation of first thread Note "No error" in "pthread_attr_setscope 1: No error". That is a bug in the test. It is using perror, but that prints errno, while the pthread functions return the error directly. Fix all cases of the same problem, by adding a new print_error function and using it. We now get: ... pthread_attr_setscope 1: Not supported (134) ... Change-Id: I972ebc931b157bc0f9084e6ecd8916a5e39238f5 --- gdb/testsuite/gdb.threads/pthreads.c | 30 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/gdb/testsuite/gdb.threads/pthreads.c b/gdb/testsuite/gdb.threads/pthreads.c index e1593e980ea..547bf0fe3f0 100644 --- a/gdb/testsuite/gdb.threads/pthreads.c +++ b/gdb/testsuite/gdb.threads/pthreads.c @@ -23,6 +23,7 @@ #include #include #include +#include static int verbose = 0; @@ -102,6 +103,14 @@ foo (int a, int b, int c) printf ("a=%d\n", a); } +/* Similar to perror, but use ERR instead of errno. */ + +static void +print_error (const char *ctx, int err) +{ + fprintf (stderr, "%s: %s (%d)\n", ctx, strerror (err), err); +} + int main (int argc, char **argv) { @@ -110,38 +119,43 @@ main (int argc, char **argv) int t = 0; void (*xxx) (); pthread_attr_t attr; + int res; if (verbose) printf ("pid = %d\n", getpid ()); foo (1, 2, 3); - if (pthread_attr_init (&attr)) + res = pthread_attr_init (&attr); + if (res != 0) { - perror ("pthread_attr_init 1"); + print_error ("pthread_attr_init 1", res); exit (1); } #ifdef PTHREAD_SCOPE_SYSTEM - if (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM)) + res = pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM); + if (res != 0) { - perror ("pthread_attr_setscope 1"); + print_error ("pthread_attr_setscope 1", res); exit (1); } #endif - if (pthread_create (&tid1, &attr, thread1, (void *) 0xfeedface)) + res = pthread_create (&tid1, &attr, thread1, (void *) 0xfeedface); + if (res != 0) { - perror ("pthread_create 1"); + print_error ("pthread_create 1", res); exit (1); } if (verbose) printf ("Made thread %ld\n", (long) tid1); sleep (1); - if (pthread_create (&tid2, NULL, thread2, (void *) 0xdeadbeef)) + res = pthread_create (&tid2, NULL, thread2, (void *) 0xdeadbeef); + if (res != 0) { - perror ("pthread_create 2"); + print_error ("pthread_create 2", res); exit (1); } if (verbose)