From patchwork Wed Sep 27 14:22:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76769 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 BF17438618E7 for ; Wed, 27 Sep 2023 14:23:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF17438618E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695824594; bh=2vUkEN2Bh+pwlwf4bNkVVMW6qHh8rBazxwiY8wmkiF4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Bhp6waXaE8N/imQNudqiiRZGzmjGQRHtxP6mYI5AKOdWI/7dM1VbWV+zfyBk1N2lJ hhyZv+v5g5Au912lQMDxiPDxi++bHYboKmI/+7nmuPDN0kXFW2RuJNXF5YGVt+n+YK CITT9Aho6uYG6Vx0FlKUKLit4anAoBlRpveS9/SQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3B4B33851AB7 for ; Wed, 27 Sep 2023 14:22:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B4B33851AB7 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-XecohNnlNrupLkFiDcOCYQ-1; Wed, 27 Sep 2023 10:22:16 -0400 X-MC-Unique: XecohNnlNrupLkFiDcOCYQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-770538a2946so2300939785a.0 for ; Wed, 27 Sep 2023 07:22:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824535; x=1696429335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2vUkEN2Bh+pwlwf4bNkVVMW6qHh8rBazxwiY8wmkiF4=; b=Zsr6E5zVpQrOfB8ra8URX0psu1StB2X1j1bHgrJWvI9LpQvxbFQ+eZWRa7jxTjgOzC WL2HJN/ewTG4oaSzCkqT8Ihr/Ww31W3jymi3y/3QTwz4JQK6N2+v7ANBK6veLQEOz9tO SaY97rZMEkFyjuO7iIE/cRRivc46W+tBab5pWlHdN8Wzz7XQXsNyiHJcis4uGW6u/XGr 0VZKJhTBhLNFnnG3h1j/CfQXciIqwoNFGyl7nTd308syixZR6ctk7ahO3LSE1qC7JbZO DbyAiWzksy2OQM5pAKSRxAmSv2wlIqQWOxzMMURJPk76y8wQtOT3wxloaudsx2aLaX1V emRQ== X-Gm-Message-State: AOJu0YxtZnnXPg2tzWLxgfR+IXn9gfqVznAmRpX8yxjv3JcYOq27gMon RnAgMMRIanjssmebfNNh2xKMxNaCSxYOppP/u6fyvdU3BnsIcfOZbk1PFYfo/M4mxt12IcMcpCU wT0pqQablDsSHwRwutxi0PQOD1M8uFbnNs/DzggmwnTpvgq27nUL5ciBtRd9AIxTGQi7sDrlB6E ePGyJOGA== X-Received: by 2002:a05:620a:d8d:b0:76f:44c:5cd0 with SMTP id q13-20020a05620a0d8d00b0076f044c5cd0mr2020828qkl.48.1695824535625; Wed, 27 Sep 2023 07:22:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBSAyIh02O2Y5upa3/910niRAF7CzGH9da3fARvVot3QgA1P0ZTA4dcXb6Wkl+2NNV7uE5dQ== X-Received: by 2002:a05:620a:d8d:b0:76f:44c:5cd0 with SMTP id q13-20020a05620a0d8d00b0076f044c5cd0mr2020811qkl.48.1695824535332; Wed, 27 Sep 2023 07:22:15 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id v14-20020ae9e30e000000b0076ef2816ff0sm3132006qkf.16.2023.09.27.07.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:22:15 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 3/5] gdb: remove use of a static buffer for building error strings Date: Wed, 27 Sep 2023 15:22:03 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed in procfs.c that we use a static buffer for building error strings when we could easily use std::string and string_printf to achieve the same result, this commit does that. I ran into this while performing a further refactor/cleanup that will be presented in a later patch in this series, and thought this was worth splitting out into its own patch. As far as I can tell, only Solaris uses procfs.c, so I did a test build on a Solaris machine, and I don't believe that I've broken anything. There should be no user visible changes after this commit. --- gdb/procfs.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/gdb/procfs.c b/gdb/procfs.c index 9443b074483..706ccf0965c 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -255,8 +255,6 @@ typedef struct procinfo { int threads_valid: 1; } procinfo; -static char errmsg[128]; /* shared error msg buffer */ - /* Function prototypes for procinfo module: */ static procinfo *find_procinfo_or_die (int pid, int tid); @@ -595,17 +593,19 @@ static void proc_resume (procinfo *pi, ptid_t scope_ptid, static void proc_warn (procinfo *pi, const char *func, int line) { - xsnprintf (errmsg, sizeof (errmsg), "procfs: %s line %d, %s", - func, line, pi->pathname); - print_sys_errmsg (errmsg, errno); + int saved_errno = errno; + std::string errmsg + = string_printf ("procfs: %s line %d, %s", func, line, pi->pathname); + print_sys_errmsg (errmsg.c_str (), saved_errno); } static void proc_error (procinfo *pi, const char *func, int line) { - xsnprintf (errmsg, sizeof (errmsg), "procfs: %s line %d, %s", - func, line, pi->pathname); - perror_with_name (errmsg); + int saved_errno = errno; + std::string errmsg + = string_printf ("procfs: %s line %d, %s", func, line, pi->pathname); + perror_with_name (errmsg.c_str (), saved_errno); } /* Updates the status struct in the procinfo. There is a 'valid' @@ -1805,11 +1805,12 @@ do_attach (ptid_t ptid) if (!open_procinfo_files (pi, FD_CTL)) { - gdb_printf (gdb_stderr, "procfs:%d -- ", __LINE__); - xsnprintf (errmsg, sizeof (errmsg), - "do_attach: couldn't open /proc file for process %d", - ptid.pid ()); - dead_procinfo (pi, errmsg, NOKILL); + int saved_errno = errno; + std::string errmsg + = string_printf ("procfs:%d -- do_attach: couldn't open /proc " + "file for process %d", __LINE__, ptid.pid ()); + errno = saved_errno; + dead_procinfo (pi, errmsg.c_str (), NOKILL); } /* Stop the process (if it isn't already stopped). */