From patchwork Thu Sep 28 14:00:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76844 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 C740A387544A for ; Thu, 28 Sep 2023 14:01:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C740A387544A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695909707; bh=2vUkEN2Bh+pwlwf4bNkVVMW6qHh8rBazxwiY8wmkiF4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=TzGerGBYzB7/kHVyDP0qSzOlS1wDM6t5YoJqEZpBVb0BLIcBNgCUJ6EuGlKLA3RD3 tyvLat6nfXAlfWgQehlkXJk25nrkG8OlHvIN3M8TZNUMwZC30vByY5VJWKZm34SIhP I2U51JbDeWH6cX04MCx4iHm4kCdI2+JBj5J06awk= 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 4654E385772B for ; Thu, 28 Sep 2023 14:00:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4654E385772B Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-26-oe2wmOXiMfCFBIgOYhYliA-1; Thu, 28 Sep 2023 10:00:57 -0400 X-MC-Unique: oe2wmOXiMfCFBIgOYhYliA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-65af1fad7f1so189361026d6.2 for ; Thu, 28 Sep 2023 07:00:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695909656; x=1696514456; 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=mhZNYHRaqHq/8DWOhNIZt1qT+ehB1vC9WPCcGlnj0RsdcpyFczBfoXOXvr/CR9RIx9 Z0Tr1kFSSwJO8UkARKu6+7db6Nk+woP3ZE2vDpfSxiQrDwnmJVB4zpQryRyg+ia8PrhI trIb5xy3hwy8oC2eGgQFxk/7zZHXxXagdVGvvoyIdmoLoxOTKpSQO7nxrXc1ChYsY+WA zL7Bp35oiLgN1B4cO3UEhZE6Zt3NAuPV/2pOjoyQSulehFKlVwXfKLUcDNFF5vFqItdm 0m3/WS8RFv0fnDdFafhHu/WGIdTNJG4vdyBPOgslOlMChKY0hQye7OQbTSjq1zmI1bxb LMcw== X-Gm-Message-State: AOJu0YxZ8ql4tFMFsHUi95dSTtxJYS06eVewyh/f8YW07lqHeWFo4+GU P1I98PE/NSxR1g88G2+jeuk9yRSd732KXRDZ84roF1UaSYT4SAsO0qMu8e/SeM0buxnzxDNhpoE lBb5hOeLI5kT0IvwhpRnmFqLLPGGdm2Ztac4HtWHmkPLvJsbFU+elvPQg31NZiofso8YFQR7MA6 sqXtoLYg== X-Received: by 2002:a0c:f5cd:0:b0:658:50c1:b1d6 with SMTP id q13-20020a0cf5cd000000b0065850c1b1d6mr1116115qvm.1.1695909656266; Thu, 28 Sep 2023 07:00:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQNQQ05PncKOwQqbvqfzIsa4tHqEbS8DrJOPYyiYkM9+MoV9CzJDs1zmF8c/Rtkf6fWWkKaA== X-Received: by 2002:a0c:f5cd:0:b0:658:50c1:b1d6 with SMTP id q13-20020a0cf5cd000000b0065850c1b1d6mr1116062qvm.1.1695909655577; Thu, 28 Sep 2023 07:00:55 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id v6-20020a0cdd86000000b0065af657ddf7sm4710392qvk.144.2023.09.28.07.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 07:00:55 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 3/5] gdb: remove use of a static buffer for building error strings Date: Thu, 28 Sep 2023 15:00:42 +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). */