From patchwork Wed Sep 27 14:22:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76765 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 D9B083875423 for ; Wed, 27 Sep 2023 14:22:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9B083875423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695824560; bh=fDRK7sZVfhWRH3K+plhIltRZoIdA9kjNMM1Cyk8reA4=; 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=Gj0mT+MTBwCFlZNj8XpNZDA19k6V6OcC1LjVNvhGNjO/LuR3GIJDt4CNYM2V2U5zW j4I+pqK3MVwrfZyoUAOGFt/XRlbqTsr9LM7pJXvJsAL6OCEr0i7BqivmJXot2nxABr iYMPloDgB+tMsJUhL2ULj7N96/5AF54wh2uwKG7Y= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 334693856DF2 for ; Wed, 27 Sep 2023 14:22:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 334693856DF2 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-wrHTMPtaP0eTU9cvW_qY5A-1; Wed, 27 Sep 2023 10:22:12 -0400 X-MC-Unique: wrHTMPtaP0eTU9cvW_qY5A-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7742bab9c0cso1322684685a.3 for ; Wed, 27 Sep 2023 07:22:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824531; x=1696429331; 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=fDRK7sZVfhWRH3K+plhIltRZoIdA9kjNMM1Cyk8reA4=; b=hVWFiWoX5b2Rs6U2yRYAbCNojD+/LB+v/gJZwQADFJ0VQJlKgqwm56TddjVRNa4HDQ XoiJuXtlO5jZaIQvQkJZ0Vz07rzEDLmtJcoVkbaBvH936f4d1z5nqOwn0AHMMxLFxt+q J/pKbapzfu0W5XnulwukxG9TxN8R9N+LlG2r0/SKP8df+CtpepO3D4BJKmlJsvABUCfn nNTeCa2Q9w/OwD6svFodakcRU5/Wb6Z+AwZxCczgSf+FhXj8d3I1e+PwiwwzgdfP6s6U VxUdQ2n5soZ6WsFxvmUkGkCUfyC7XsKhp2taREKNrDCEamubTjHK/nS9gtSNmgIBT+Wu B47A== X-Gm-Message-State: AOJu0Yxwh0dCzYp6LZTU+GL18ZWG6brx0Bjlhk9x4VXWjocjU3AxKDLq X9DkEY67IpxfLRrRv21pRrlHFoUbdPFOAAMregKvJGLlkFDIEZxIbWVT23K9vsLwJSnUnQ96iAg GVBDkOszPG7v8sDHfOeKFwd6Xg1BTlK5lrA3zpw6Vkb/Gvdr7TJ6zdwKmEfLYP9+x3GoIb0iHdq +Jxf0KZQ== X-Received: by 2002:ae9:e708:0:b0:774:1455:110a with SMTP id m8-20020ae9e708000000b007741455110amr2085549qka.63.1695824531779; Wed, 27 Sep 2023 07:22:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECRsfoiY4aIc+FW7IfkAXQ5nLhuS5SvB0mv5LPzZ+CC87xaVqseB7NSbj5BcvN5wJAIbvu+A== X-Received: by 2002:ae9:e708:0:b0:774:1455:110a with SMTP id m8-20020ae9e708000000b007741455110amr2085526qka.63.1695824531396; Wed, 27 Sep 2023 07:22:11 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id j21-20020ae9c215000000b0076d9e298928sm5474404qkg.66.2023.09.27.07.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:22:11 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 1/5] gdb: some additional filename styling Date: Wed, 27 Sep 2023 15:22:01 +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.5 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_H4, 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" Fix up another couple of places where we can apply filename styling. --- gdb/source.c | 3 ++- gdb/symfile.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gdb/source.c b/gdb/source.c index 9c701e866a6..5bdd729be8b 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -594,7 +594,8 @@ add_path (const char *dirname, char **which_path, int parse_separators) print_sys_errmsg (name, save_errno); } else if ((st.st_mode & S_IFMT) != S_IFDIR) - warning (_("%s is not a directory."), name); + warning (_("%ps is not a directory."), + styled_string (file_name_style.style (), name)); } append: diff --git a/gdb/symfile.c b/gdb/symfile.c index 76b5e1b8fe7..19cf9c911f9 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2482,8 +2482,9 @@ reread_symbols (int from_tty) if (res != 0) { /* FIXME, should use print_sys_errmsg but it's not filtered. */ - gdb_printf (_("`%s' has disappeared; keeping its symbols.\n"), - objfile_name (objfile)); + gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"), + styled_string (file_name_style.style (), + objfile_name (objfile))); continue; } new_modtime = new_statbuf.st_mtime; From patchwork Wed Sep 27 14:22:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76766 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 7A7493861938 for ; Wed, 27 Sep 2023 14:22:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A7493861938 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695824563; bh=xXdVV19XEOQNZFTJ9C6xPgo4KpQOTE1+CO72pdQ9s0E=; 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=tMz5pPdAwE2uOtr4oSYlcmmOiTw9GSZlHBfpGz6S2dWMX2un69UvvxsHF+XhymUM/ 98NuxjJ6lSwTnNV3kgTnI4hrz5DBJ4H2a01SyR3/vT4uNu/i7ukjUYrtq517suI/8M Dv14lMpj+1pOHpE7hNfMA/uVtCbivGM7J2Zjvh10= 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 08DB53861807 for ; Wed, 27 Sep 2023 14:22:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08DB53861807 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-9VFJ7SSEOSm6dXNJ-4ublg-1; Wed, 27 Sep 2023 10:22:14 -0400 X-MC-Unique: 9VFJ7SSEOSm6dXNJ-4ublg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-774294bde69so861353085a.1 for ; Wed, 27 Sep 2023 07:22:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824534; x=1696429334; 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=xXdVV19XEOQNZFTJ9C6xPgo4KpQOTE1+CO72pdQ9s0E=; b=G5oytxne2TyM4HZydffBJzrO28cOQE3D41iafZihiCZJ/uvV8lpaPEXJx9Q91G/eWt BApbk+uWYeGDLgUsCUTXY4eenJtNSLgX67q+AHdySKsMH+rVg7eIuyYgezxVpVT8UPJw E0GgjPF76WWKmeIegE4xtz7EILn9ZM9UXggBwvykg6TSNT8xw5rwXU54gz9wybwXgTRJ FJK0Qqo5m1YeBCH+Ij4NmF8WKhMMFsWpmkhtgp+C6BN/QQYiCbGdwquTnEL8Xinlw3Ea OK+hb7SZjju7JbtXM+LAWGvUe8L1/4SojxgzhQLlmrlJij3hUB8o54U23S41oPQ4zUlW rcdg== X-Gm-Message-State: AOJu0YyDHBkSqZBJoe+jttjeNKEoq2CzYo6aLxKrOLz80MwLDk1iIicJ gmxfLPPq5B5c5m8kB8W2SPBtAYMK5HlrtaTqoY5z3oEjUBLZOLl7uy6+phGrzr5Hata5UFF0R4d gWJqsl2Dork0uubFHTVz1w7v6ee3htt6A53pKZ1f+7xpzDC+Ak0uq7NvhRA0FgydGMbCJW5EcrI bL+qwP8Q== X-Received: by 2002:a05:620a:28ca:b0:767:ea44:daf9 with SMTP id l10-20020a05620a28ca00b00767ea44daf9mr6317245qkp.31.1695824533740; Wed, 27 Sep 2023 07:22:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFy9TkYrbhW2fEe92FNztBlUsMatOXvoivhYuKkXGvPn6C/+U5eubAIq/V7KAUiGpHVTHpliA== X-Received: by 2002:a05:620a:28ca:b0:767:ea44:daf9 with SMTP id l10-20020a05620a28ca00b00767ea44daf9mr6317210qkp.31.1695824533373; Wed, 27 Sep 2023 07:22:13 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id x2-20020a05620a14a200b007756e75b91bsm863828qkj.78.2023.09.27.07.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:22:13 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 2/5] gdb: use archive name in warning when appropriate Date: Wed, 27 Sep 2023 15:22:02 +0100 Message-Id: <0611bf29b93059df312acf56601cd45398e7dd0e.1695824275.git.aburgess@redhat.com> 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" While working on some other patch I noticed that in reread_symbols there is a diagnostic message that can be printed, and in some cases we might use the wrong filename in the message. The code in question is checking to see if an objfile has changed on disk, we do this by stat-ing the on disk file and checking the mtime. If this file has been removed from disk then we print a message that the file has been removed, however, if the objfile is within an archive then we stat the archive itself, but then warn that the component within the archive has disappeared. I think it makes more sense to say that the archive has disappeared. The last related commit is this one: commit 02aeec7bde8ec8a04d14a5637e75f1c6ab899e23 Date: Tue Apr 27 21:01:30 2010 +0000 Check library name rather than member name when rereading symbols. Though this just makes the code to stat the archive unconditional, the code in question existed before this commit. However, the above commit doesn't include any tests, and seems to indicate that the problem being addressed was seen on Darwin. I'm not sure how to setup a test where GDB is using an objfile from within an archive, and so there's no tests for this commit... ... but if someone can let me know how I can setup a suitable test, please let me know and I'll try to get something working. --- gdb/symfile.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index 19cf9c911f9..145621f3c67 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2459,7 +2459,6 @@ reread_symbols (int from_tty) { long new_modtime; struct stat new_statbuf; - int res; std::vector new_objfiles; for (objfile *objfile : current_program_space->objfiles ()) @@ -2475,16 +2474,18 @@ reread_symbols (int from_tty) `ar', often called a `static library' on most systems, though a `shared library' on AIX is also an archive), then you should stat on the archive name, not member name. */ + const char *filename; if (objfile->obfd->my_archive) - res = stat (bfd_get_filename (objfile->obfd->my_archive), &new_statbuf); + filename = bfd_get_filename (objfile->obfd->my_archive); else - res = stat (objfile_name (objfile), &new_statbuf); + filename = objfile_name (objfile); + + int res = stat (filename, &new_statbuf); if (res != 0) { /* FIXME, should use print_sys_errmsg but it's not filtered. */ gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"), - styled_string (file_name_style.style (), - objfile_name (objfile))); + styled_string (file_name_style.style (), filename)); continue; } new_modtime = new_statbuf.st_mtime; 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). */ From patchwork Wed Sep 27 14:22:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76767 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 A571E3870C1C for ; Wed, 27 Sep 2023 14:22:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A571E3870C1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695824574; bh=5Skbye1pbdleF3T0AL5mnoSwVxBekNvHYr5HKE9NXYw=; 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=cL/jycMI2PW1B17AzOzNtTHW5T65iFcLSMUd0zBBfnlZtZpQwhNJnj7obuj1r4sat HNvhQJCTgcpBt9jbBKRS2rVM9qPuYUBtTJEuhkOHnBYHtIQe9DmXHOdJafeEUgJunM oQ5DMOtL9dNiz0o/CtHjklm8JkLXDqYKfo0iZNRo= 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 D3A3B38618D0 for ; Wed, 27 Sep 2023 14:22:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D3A3B38618D0 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-5E6keGmmMYqdtHFKpUEGAA-1; Wed, 27 Sep 2023 10:22:18 -0400 X-MC-Unique: 5E6keGmmMYqdtHFKpUEGAA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-65b0af1b0e2so124558676d6.0 for ; Wed, 27 Sep 2023 07:22:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824538; x=1696429338; 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=5Skbye1pbdleF3T0AL5mnoSwVxBekNvHYr5HKE9NXYw=; b=AVpV/fkVbd37HYNQv/JJPTBDQWqEf5bHO9esDPz1D15W/wKQ6yWNoz86Nu5kkXOG2u dwOjj9Z0ebH53RyzMAU1JZmyzyYlM/1vaNBjGtTqR45hUIbalpkudsCQCRF9i2t7ulHv Ljc0mlUmNsXk05nv9vr7Z9pm78Y5KIad/D5vXPf9ojm7+Q9OPPVukXFTIUY5DhYeOg9V H5OdLPBlBm54lmQowV4PqbX6GzHTWmBg0P5CQMEWwjXGwnIooJLt1VMAXMSlYXbMCIag csb/tHnxUEa41ZObY4zyv/bchn5JEuuV8Fr8wu4qmCHXPK3EoSIn2ediOzrurvliP/7/ SLvg== X-Gm-Message-State: AOJu0YzZsI8q8OlqowDY9daKd4HE7YrJAnFSj1cP8a8xO1F9OaH3b3Xm u9kgjTurUDVZ93Ge9FUyBMj1FB1m1yV2wd7ytDJyyCcKJjchm4ydMptQjNijLH729+17/plYPE7 DjbTCI+DA+tIYl0zdyIh+734mYx8H0QIkQOQuWR2yb4K8oI/IOCh7AnBnQQex/SEZNnra58B9xW y/gez7Ag== X-Received: by 2002:a05:6214:b2b:b0:65c:fec5:6f0 with SMTP id w11-20020a0562140b2b00b0065cfec506f0mr1731719qvj.45.1695824537725; Wed, 27 Sep 2023 07:22:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUJOEtA//T38ywQUhZ+MW6wz5XrtqXG9EfNYq37ml+OWPAXXDHKAmoVdAxVS8/GOfhTeRaLA== X-Received: by 2002:a05:6214:b2b:b0:65c:fec5:6f0 with SMTP id w11-20020a0562140b2b00b0065cfec506f0mr1731697qvj.45.1695824537285; Wed, 27 Sep 2023 07:22:17 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id t12-20020a05620a004c00b00767dcf6f4adsm3363471qkt.51.2023.09.27.07.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:22:17 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 4/5] gdb: remove print_sys_errmsg Date: Wed, 27 Sep 2023 15:22:04 +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.5 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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" This started with me running into this comment in symfile.c: /* FIXME, should use print_sys_errmsg but it's not filtered. */ gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"), styled_string (file_name_style.style (), filename)); In this particular case I think I disagree with the comment; I think the output should be a warning rather than just a message printed to gdb_stdout, I think when the executable, or some other objfile that is currently being debugged, disappears from disk, this is likely an unexpected situation, and worth warning the user about. So, in theory, I could just call print_sys_errmsg and remove the comment, but that would mean loosing the filename styling in the output... so in the end I remove the comment and updated the code to call warning. But that got me looking at print_sys_errmsg and how it's used. Currently the function takes a string and an errno, and prints, to stderr, the string followed by the result of calling strerror on the errno. In some places the string passed to print_sys_errmsg is just a filename, and this is used when something goes wrong. In these cases, I think calling warning rather than gdb_printf to gdb_stderr, would be better, and in fact, in a couple of places we manually print a "warning" prefix, and then call print_sys_errmsg. And so, for these users I have added a new function warning_filename_and_errno, which takes a filename, which is printed with styling, and an errno, which is passed through strerror and the resulting string printed. This new function calls warning to print its output. I then updated some of the print_sys_errmsg users to use this new function. Some other users of print_sys_errmsg are also emitting what is clearly a warning, however, the string being passed in is more than just a filename, so the new warning_filename_and_errno function can't be used, it would style the whole string. For these users I have switched to calling warning directly, this allows me to style the warning message correctly. Finally, in inflow.c there is one last call to print_sys_errmsg, in this case I just inlined the definition of print_sys_errmsg. This is a really weird case, as after printing this message GDB just does a hard exit. This is pretty old code, dating back to the initial GDB import, I guess it should be updated to call error() maybe, but I'm reluctant to make this change as part of this commit, just in case there's some reason why we can't throw an error at this point. With that done there are now no users of print_sys_errmsg, and so the old function can be removed. While I was doing all of the above I added some additional filename styling in soure.c, this is in an else block where the if contained the print_sys_errmsg call, so these felt related. And finally, while I was updating the uses of print_sys_errmsg in procfs.c, I noticed that we used a static errmsg buffer to format some error strings. As the above changes got rid of one of the users of errmsg I also removed the other two users, and the static buffer. --- gdb/inflow.c | 3 ++- gdb/main.c | 7 +------ gdb/procfs.c | 17 ++++++++++------- gdb/source.c | 15 ++++----------- gdb/symfile.c | 5 ++--- gdb/utils.c | 9 ++++----- gdb/utils.h | 8 +++++++- gdb/windows-nat.c | 2 +- 8 files changed, 31 insertions(+), 35 deletions(-) diff --git a/gdb/inflow.c b/gdb/inflow.c index 767cfd02c48..095c5f03672 100644 --- a/gdb/inflow.c +++ b/gdb/inflow.c @@ -766,7 +766,8 @@ check_syscall (const char *msg, int result) { if (result < 0) { - print_sys_errmsg (msg, errno); + gdb_printf (gdb_stderr, "%s:%s.\n", msg, + safe_strerror (errno)); _exit (1); } } diff --git a/gdb/main.c b/gdb/main.c index cf46f6acb20..1ca0fdeee1b 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -115,12 +115,7 @@ set_gdb_data_directory (const char *new_datadir) struct stat st; if (stat (new_datadir, &st) < 0) - { - int save_errno = errno; - - gdb_printf (gdb_stderr, "Warning: "); - print_sys_errmsg (new_datadir, save_errno); - } + warning_filename_and_errno (new_datadir, errno); else if (!S_ISDIR (st.st_mode)) warning (_("%ps is not a directory."), styled_string (file_name_style.style (), new_datadir)); diff --git a/gdb/procfs.c b/gdb/procfs.c index 706ccf0965c..48e9f3dd4b5 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -46,6 +46,7 @@ #include "gdbsupport/scoped_fd.h" #include "gdbsupport/pathstuff.h" #include "gdbsupport/buildargv.h" +#include "cli/cli-style.h" /* This module provides the interface between GDB and the /proc file system, which is used on many versions of Unix @@ -558,7 +559,7 @@ enum { NOKILL, KILL }; static void dead_procinfo (procinfo *pi, const char *msg, int kill_p) { - print_sys_errmsg (pi->pathname, errno); + warning_filename_and_errno (pi->pathname, errno); if (kill_p == KILL) kill (pi->pid, SIGKILL); @@ -594,18 +595,20 @@ static void proc_warn (procinfo *pi, const char *func, int line) { 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); + warning ("procfs: %s line %d, %ps: %s", + func, line, styled_string (file_name_style.style (), + pi->pathname), + safe_strerror (saved_errno)); } static void proc_error (procinfo *pi, const char *func, int line) { 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); + error ("procfs: %s line %d, %ps: %s", + func, line, styled_string (file_name_style.style (), + pi->pathname), + safe_strerror (saved_errno)); } /* Updates the status struct in the procinfo. There is a 'valid' diff --git a/gdb/source.c b/gdb/source.c index 5bdd729be8b..f648adc4520 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -587,12 +587,7 @@ add_path (const char *dirname, char **which_path, int parse_separators) a directory/etc, then having them in the path should be harmless. */ if (stat (name, &st) < 0) - { - int save_errno = errno; - - gdb_printf (gdb_stderr, "Warning: "); - print_sys_errmsg (name, save_errno); - } + warning_filename_and_errno (name, errno); else if ((st.st_mode & S_IFMT) != S_IFDIR) warning (_("%ps is not a directory."), styled_string (file_name_style.style (), name)); @@ -1341,11 +1336,9 @@ print_source_lines_base (struct symtab *s, int line, int stopline, if (!(flags & PRINT_SOURCE_LINES_NOERROR)) { const char *filename = symtab_to_filename_for_display (s); - int len = strlen (filename) + 100; - char *name = (char *) alloca (len); - - xsnprintf (name, len, "%d\t%s", line, filename); - print_sys_errmsg (name, errcode); + warning (_("%d\t%ps: %s"), line, + styled_string (file_name_style.style (), filename), + safe_strerror (errcode)); } else { diff --git a/gdb/symfile.c b/gdb/symfile.c index 145621f3c67..10074e281bd 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2483,9 +2483,8 @@ reread_symbols (int from_tty) int res = stat (filename, &new_statbuf); if (res != 0) { - /* FIXME, should use print_sys_errmsg but it's not filtered. */ - gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"), - styled_string (file_name_style.style (), filename)); + warning (_("`%ps' has disappeared; keeping its symbols."), + styled_string (file_name_style.style (), filename)); continue; } new_modtime = new_statbuf.st_mtime; diff --git a/gdb/utils.c b/gdb/utils.c index 2f545337cd4..a191d26a007 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -619,14 +619,13 @@ perror_warning_with_name (const char *string) warning (_("%s"), combined.c_str ()); } -/* Print the system error message for ERRCODE, and also mention STRING - as the file name for which the error was encountered. */ +/* See utils.h. */ void -print_sys_errmsg (const char *string, int errcode) +warning_filename_and_errno (const char *filename, int saved_errno) { - const char *err = safe_strerror (errcode); - gdb_printf (gdb_stderr, "%s: %s.\n", string, err); + warning (_("%ps: %s"), styled_string (file_name_style.style (), filename), + safe_strerror (saved_errno)); } /* Control C eventually causes this to be called, at a convenient time. */ diff --git a/gdb/utils.h b/gdb/utils.h index c5364fa4b35..f646b300530 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -275,7 +275,13 @@ extern void fprintf_symbol (struct ui_file *, const char *, extern void perror_warning_with_name (const char *string); -extern void print_sys_errmsg (const char *, int); +/* Issue a warning formatted as ': ', where + is FILENAME with filename styling applied. As such, don't + pass anything more than a filename in this string. The + is a string returned from calling safe_strerror(SAVED_ERRNO). */ + +extern void warning_filename_and_errno (const char *filename, + int saved_errno); /* Warnings and error messages. */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 5a897dbfe76..7a139c8d36f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2625,7 +2625,7 @@ windows_nat_target::create_inferior (const char *exec_file, tty = open (inferior_tty.c_str (), O_RDWR | O_NOCTTY); if (tty < 0) { - print_sys_errmsg (inferior_tty.c_str (), errno); + warning_filename_and_errno (inferior_tty.c_str (), errno); ostdin = ostdout = ostderr = -1; } else From patchwork Wed Sep 27 14:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76768 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 C2B99387103C for ; Wed, 27 Sep 2023 14:23:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2B99387103C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695824582; bh=veFP/L2Tw1GxHWcyLm61FadByn6i0GWosFeRJ7w3E7c=; 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=hDwSRiGzQETep1YumZjhH6VukFdI7zz/+PQ+BOh+Tzrr1NOeQYQZA2UxCXHXgdJMZ 89y4Ojm6Ybz/miivmoKrG1aK+tWDQ0nb3GtMGxPWzOeosjsO0htrmGFmRG/UshcUB5 9tTWdvOfsKXTf8bSB2Qbb0CwXJCjbWJfFML9F9YM= 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 EF2B9385559E for ; Wed, 27 Sep 2023 14:22:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF2B9385559E Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-EZIykRoMN7mQUGMDHLxq5A-1; Wed, 27 Sep 2023 10:22:20 -0400 X-MC-Unique: EZIykRoMN7mQUGMDHLxq5A-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-774269fffe7so846087485a.0 for ; Wed, 27 Sep 2023 07:22:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824540; x=1696429340; 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=veFP/L2Tw1GxHWcyLm61FadByn6i0GWosFeRJ7w3E7c=; b=Nw+9q3HYfDA+HEd3gntBDNyBEcq6+dDQFex6mTFJEAx9QJKvu/1Zf/nDSWbm1eVhb1 2/rmLBm0Sv5+7V/XK+15i1vGmJ/fIeNdAREMRYSsSZUKZVL4DA92nW8VlPkoLJo6xsKF dTypSZEAuhbEr+NfyPmQufmji4MNe9bwARQemg4+hDsl/LtxbabuYF1A2h596OiK0vJm /A5AgOUzXYgU4iq7vmqTsNZpDAujyVCRbKtVfuO6qEi5w1tYUbtaBJejnVtLIE1G1bAg f1XkSCRK4czV2P7eE+AA1347jD76QSZvi8YUbUZ9uVJq1agOydsfLjAjP/7kHTXHz1GP fp8A== X-Gm-Message-State: AOJu0YzqX90+hd6TnEo4Vocx1TnQVwnm0h3IdslUEWyUA1+A4tMoipIf SIaYayOc8Y4ayhbVTmuVyllXYPwfEyppNZMXSzQ6yNYaa0xs1u3Qov6UoLfLiCEnRBVzTemNCur Uj5AOV/Q5FeagCNbc4mky5RAc86TqUxZ+qZAmtaWXKLblOXRlhQjmyopDNmPFgpwkY39OhIsvnn m6Pd4o2Q== X-Received: by 2002:a05:620a:44c9:b0:76e:f686:cad8 with SMTP id y9-20020a05620a44c900b0076ef686cad8mr6884866qkp.13.1695824539657; Wed, 27 Sep 2023 07:22:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEX9JURgMbIOZ1ERuFTtSiho9Hg4kfQ0A9S5m1ZZ1zqEEmz+2v49Y9h4ML99fWs0q38qIyrWA== X-Received: by 2002:a05:620a:44c9:b0:76e:f686:cad8 with SMTP id y9-20020a05620a44c900b0076ef686cad8mr6884835qkp.13.1695824539183; Wed, 27 Sep 2023 07:22:19 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b007756d233fbdsm968794qkl.37.2023.09.27.07.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:22:18 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 5/5] gdb: fix reread_symbols when an objfile has target: prefix Date: Wed, 27 Sep 2023 15:22:05 +0100 Message-Id: <70ba713f7bbc6ac07de7dbdbfa186d6d3c37df5d.1695824275.git.aburgess@redhat.com> 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=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, 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" When using a remote target, it is possible to tell GDB that the executable to be debugged is located on the remote machine, like this: (gdb) target extended-remote :54321 ... snip ... (gdb) file target:/tmp/hello.x Reading /tmp/hello.x from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /tmp/hello.x from remote target... Reading symbols from target:/tmp/hello.x... (gdb) So far so good. However, when we try to start the inferior we run into a small problem: (gdb) set remote exec-file /tmp/hello.x (gdb) start `target:/tmp/hello.x' has disappeared; keeping its symbols. Temporary breakpoint 1 at 0x401198: file /tmp/hello.c, line 18. Starting program: target:/tmp/hello.x ... snip ... Temporary breakpoint 1, main () at /tmp/hello.c:18 18 printf ("Hello World\n"); (gdb) Notice this line: `target:/tmp/hello.x' has disappeared; keeping its symbols. That's wrong, the executable hasn't been removed, GDB just doesn't know how to check if the remote file has changed, and so falls back to assuming that the file has been removed. In this commit I add support to reread_symbols for stat-ing remote files. With this in place GDB no longer complains when using a remote executable file. --- gdb/symfile.c | 19 +- gdb/target.c | 15 ++ gdb/target.h | 39 ++++ gdb/testsuite/gdb.server/target-exec-file.c | 22 +++ gdb/testsuite/gdb.server/target-exec-file.exp | 174 ++++++++++++++++++ 5 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.server/target-exec-file.c create mode 100644 gdb/testsuite/gdb.server/target-exec-file.exp diff --git a/gdb/symfile.c b/gdb/symfile.c index 10074e281bd..b21c8ead225 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2480,7 +2480,24 @@ reread_symbols (int from_tty) else filename = objfile_name (objfile); - int res = stat (filename, &new_statbuf); + int res; + if (is_target_filename (filename)) + { + fileio_error target_errno; + + scoped_target_fileio_open fd (nullptr, + (filename + + strlen (TARGET_SYSROOT_PREFIX)), + FILEIO_O_RDONLY, 0, false, + &target_errno); + if (fd.get () == -1) + res = -1; + else + res = target_fileio_fstat (fd.get (), &new_statbuf, + &target_errno); + } + else + res = stat (filename, &new_statbuf); if (res != 0) { warning (_("`%ps' has disappeared; keeping its symbols."), diff --git a/gdb/target.c b/gdb/target.c index 8cb4fa1736d..0d1608bb5fe 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -54,6 +54,7 @@ #include "target-connection.h" #include "valprint.h" #include "cli/cli-decode.h" +#include "cli/cli-style.h" static void generic_tls_error (void) ATTRIBUTE_NORETURN; @@ -3577,6 +3578,20 @@ target_fileio_read_stralloc (struct inferior *inf, const char *filename) return gdb::unique_xmalloc_ptr (bufstr); } +/* See target.h. */ + +scoped_target_fileio_open::~scoped_target_fileio_open () +{ + if (m_fd != -1) + { + fileio_error target_errno; + if (target_fileio_close (m_fd, &target_errno) != 0) + warning (_("failed to close %ps: %s"), + styled_string (file_name_style.style (), + m_filename.c_str ()), + safe_strerror (fileio_error_to_host (target_errno))); + } +} static int default_region_ok_for_hw_watchpoint (struct target_ops *self, diff --git a/gdb/target.h b/gdb/target.h index 936ae79219c..5712adc367d 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -2235,6 +2235,45 @@ extern gdb::unique_xmalloc_ptr target_fileio_read_stralloc with EIO. */ extern void fileio_handles_invalidate_target (target_ops *targ); +/* A class that performs a target_fileio_open within a scope. On leaving + the scope target_fileio_close is called. + + If the close fails then a warning is issued. */ +struct scoped_target_fileio_open +{ + /* Call target_fileio_open passing all the arguments through. See + target_fileio_open for the meaning of all arguments. */ + scoped_target_fileio_open (struct inferior *inf, + const char *filename, int flags, + int mode, bool warn_if_slow, + fileio_error *target_errno) + : m_filename (filename) + { + m_fd = target_fileio_open (inf, filename, flags, mode, warn_if_slow, + target_errno); + } + + /* Close the file that was opened in the constructor, issue a warning if + the close fails. */ + ~scoped_target_fileio_open (); + + /* Return the file descriptor for the opened file. This can only be used + with target_fileio_* calls. This will return -1 if the open failed. */ + int get () const + { + return m_fd; + } + +private: + /* The filename that we opened. Stored so we can give a warning if the + close fails for any reason. */ + std::string m_filename; + + /* The target file descriptor for the opened file, or -1 if the open + failed for any reason. */ + int m_fd = -1; +}; + /* Tracepoint-related operations. */ extern void target_trace_init (); diff --git a/gdb/testsuite/gdb.server/target-exec-file.c b/gdb/testsuite/gdb.server/target-exec-file.c new file mode 100644 index 00000000000..3a264f239ed --- /dev/null +++ b/gdb/testsuite/gdb.server/target-exec-file.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 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 . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.server/target-exec-file.exp b/gdb/testsuite/gdb.server/target-exec-file.exp new file mode 100644 index 00000000000..9260df8b88d --- /dev/null +++ b/gdb/testsuite/gdb.server/target-exec-file.exp @@ -0,0 +1,174 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2023 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 . + +# Test GDB's handling of using a file with a 'target:' prefix as the +# executable file. This test includes checking what happens when the +# file on the target system changes and GDB needs to reload it. + +load_lib gdbserver-support.exp + +require allow_gdbserver_tests !use_gdb_stub + +standard_testfile + +if { [build_executable "failed to prepare" $testfile $srcfile debug] } { + return -1 +} + +clean_restart + +# Some boards specifically set the sysroot to the empty string to +# avoid copying files from the target. But for this test we do want +# to copy files from the target, so set the sysroot back to 'target:'. +# +# This is fine so long as we're not using a board file that sets the +# sysroot to something else -- but none of the standard boards do +# this, and plenty of other tests mess with the sysroot, so I guess we +# don't worry about that too much. +gdb_test "set sysroot target:" ".*" + +# Make sure we're disconnected, in case we're testing with an +# extended-remote board, therefore already connected. +gdb_test "disconnect" ".*" + +# Ensure the executable is on the target. +set target_exec [gdb_remote_download target $binfile] + +# We're going to be restarting the inferior. Lets ask GDB not to +# prompt us if this is the right thing to do. +gdb_test_no_output "set confirm off" + +# Start gdbserver, but always in extended-remote mode, and then +# connect to it from GDB. +set res [gdbserver_start "--multi" $target_exec] +set gdbserver_protocol "extended-remote" +set gdbserver_gdbport [lindex $res 1] +gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport + +# Issue a 'file' command and parse the output. We look for a couple +# of specific things to ensure that we are correctly reading the exec +# from the remote target. +set saw_read_of_remote_exec false +set saw_read_of_syms_from_exec false +gdb_test_multiple "file target:$target_exec" "run file command" { + -re "^file target:\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^Reading (\[^\r\n\]+) from remote target\\.\\.\\.\r\n" { + set filename $expect_out(1,string) + if { $filename eq $target_exec } { + set saw_read_of_remote_exec true + } + exp_continue + } + + -re "^warning: File transfers from remote targets can be slow\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^Reading symbols from target:(\[^\r\n\]+)\\.\\.\\.\r\n" { + set filename $expect_out(1,string) + if { $filename eq $target_exec } { + set saw_read_of_syms_from_exec true + } + exp_continue + } + + -re "^Expanding full symbols from \[^\r\n\]+\r\n" { + exp_continue + } + + -re "^$gdb_prompt $" { + pass $gdb_test_name + } +} + +gdb_assert { $saw_read_of_remote_exec } \ + "exec was read from the remote target" + +gdb_assert { $saw_read_of_syms_from_exec } \ + "symbols were read from remote exec file" + +# Start the inferior (with the 'start' command), use TESTNAME for any +# pass/fail calls. EXPECT_REREAD should be true or false and +# indicates if we expect to too a line like: +# +# `FILE' has changed; re-reading symbols. +proc start_inferior { testname expect_reread } { + with_test_prefix $testname { + if { [gdb_start_cmd] < 0 } { + fail "start command" + return -1 + } + + set saw_reread false + gdb_test_multiple "" "stopped at main" { + -re "^start\\s*\r\n" { + exp_continue + } + -re "^`\[^\r\n\]+' has changed; re-reading symbols\\.\r\n" { + set saw_reread true + exp_continue + } + -re "^Reading \[^\r\n\]+ from remote target\\.\\.\\.\r\n" { + exp_continue + } + -re "^Expanding full symbols from \[^\r\n\]+\\.\\.\\.\r\n" { + exp_continue + } + -re "^Temporary breakpoint $::decimal at $::hex: \[^\r\n\]+\r\n" { + exp_continue + } + -re "^Starting program: \[^\r\n\]+\r\n" { + exp_continue + } + -re "^\\s*\r\n" { + exp_continue + } + -re "^Temporary breakpoint $::decimal, main \\(\\) at .*$::gdb_prompt $" { + pass $testname + } + } + + gdb_assert { $expect_reread == $saw_reread } \ + "check symbol re-read behaviour" + } +} + +# Start the inferior for the first time. The symbols were already +# read from the file when the 'file' command was used, we should not +# see the symbols re-read now. +start_inferior "start inferior the first time" false + +# Re-start the inferior. The executable is unchanged so we should not +# see the symbol file being re-read. +start_inferior "start inferior a second time" false + +# Delay for a short while so, when we touch the exec, we know the +# timestamp will change. +sleep 1 +set res [remote_exec target "touch $target_exec"] +set status [lindex $res 0] +if { $status != 0 } { + fail "touching executable on target" + return -1 +} + +# Start the inferior again, we expect to see the symbols being re-read +# from the remote file. +start_inferior "start inferior a third time" true