From patchwork Thu Sep 28 14:00:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76841 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 CE4213857C41 for ; Thu, 28 Sep 2023 14:01:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE4213857C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695909677; bh=fDRK7sZVfhWRH3K+plhIltRZoIdA9kjNMM1Cyk8reA4=; 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=plrHJbjkP9zkTfatYn/KnCMIn1ddEFGE6QA5DDwB4jxOPBSLBLntO5S9Bq13IrTQJ J8ts/jKHEd3BQZVJeSb7gYVLf8vM9+/A72DlPbo8egeaxuP1QvFb9jL5fl8U683D47 uoM5ZeN3otzqPQ5e03dfK5rRHWp40OcPU++FlnDQ= 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 2C5B73858C52 for ; Thu, 28 Sep 2023 14:00:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C5B73858C52 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-MsXFBydrMG6oIRjKaCh8Bg-1; Thu, 28 Sep 2023 10:00:51 -0400 X-MC-Unique: MsXFBydrMG6oIRjKaCh8Bg-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-65b1c33bf59so109589686d6.3 for ; Thu, 28 Sep 2023 07:00:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695909651; x=1696514451; 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=mla8Z6BY0RnAgi3mSGq51MjuMGBYGItp8oaAYz6vJVEPeSwYfYxYrRKxsTXay7N13t BspCWph205vMbsYn8jOlbo/LGx3B4i5AiypjZc+QAloirTnPIp6ZSPbXr7OfzvQyW4AV TY+f27sKUJnKvFCP9U3FKZew9hsgO1m5rXqtidDyyriDC9U/A0osZziu14+5h1iLJdlJ efsh+K9wK7qmD0tEor1KjCbnEazoye117EWNWj0mteb3+uTAcMzbA2lZNBLTwFolk/Rd 7Wf3GQrTNK8qhZlMhf1SzBDf79n4WghL4n/IR94uIeMmyyyntCxiI/av7iLmTGf3kMx4 HwKg== X-Gm-Message-State: AOJu0YzMfsS3HVL/xud1JG11tzQRNqLJZykEa+uJMmTJrXyUL4HUDE6G wh9qbr4Z0Hw4IQhBdn8/TW1IIt23RRaEa9mr5in52P3ja/a5I+8Yd1D+F+IOl4ZO76WwTgIU0xm kMZtcUC+5rmHg1wXMKWr8Vg38Y78fv6olLe681qCzOxEH54L9KVpGv8Y05egx3YKGt+d740flhc k4+6283A== X-Received: by 2002:a0c:f4cf:0:b0:64f:7fe6:bf1d with SMTP id o15-20020a0cf4cf000000b0064f7fe6bf1dmr1250806qvm.12.1695909650810; Thu, 28 Sep 2023 07:00:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZJegnA7+SeQSSw+KsIlXHddQJb6/zbtqhfuFmg0m/Trr8pFx5WeLVwDcII7ywjOOOgJgpKw== X-Received: by 2002:a0c:f4cf:0:b0:64f:7fe6:bf1d with SMTP id o15-20020a0cf4cf000000b0064f7fe6bf1dmr1250767qvm.12.1695909650372; Thu, 28 Sep 2023 07:00:50 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id q17-20020a0ce211000000b0065655bb349csm2427421qvl.141.2023.09.28.07.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 07:00:50 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 1/5] gdb: some additional filename styling Date: Thu, 28 Sep 2023 15:00:40 +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" 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 Thu Sep 28 14:00:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76842 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 870763865C15 for ; Thu, 28 Sep 2023 14:01:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 870763865C15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695909684; bh=xXdVV19XEOQNZFTJ9C6xPgo4KpQOTE1+CO72pdQ9s0E=; 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=kciXBR2yhXgmdBh44mVI80p9orIFk+QxQYevbWzOM510KIhLQazpaTUqIZoII4Mx0 fvzNUXYqVj2/0KWkGcn8/YLF4plYy40TjyonO9u+WWeroX704B5eRAl7yw1nJKfoYS 5cVf+/5B0r+B/pjpa74JWZ4fDL7ZwD/ymyi6Hb08= 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 A622B38618FA for ; Thu, 28 Sep 2023 14:00:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A622B38618FA Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-577-4n8O-WGCMluhERU2tUrL4w-1; Thu, 28 Sep 2023 10:00:53 -0400 X-MC-Unique: 4n8O-WGCMluhERU2tUrL4w-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-65afb74699eso179209246d6.3 for ; Thu, 28 Sep 2023 07:00:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695909653; x=1696514453; 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=A+/VIAZ/s0YG3LzeFVjx0IhFEEPVSox/wztqJVzC66PMu3tQTV/WRal+YHj8vO6Vin WKkPKDtq4IjYziHZa0FBZJEqmAUC2pv88BSImrEeDy5OfATsd48Fb7OoX1D2fykIkt2x 1QWS07d0YkIgj//QokOBRoyJXL+3nECVhexNlGZCJ/8OSL1t5atV2nI5IatI/VtOdQrC iLlYGZIo/5lnRk4YpHKPj5UKVqyQTjsCM2AzNvIiDLQ3ex29sSBzLY3ie0at0aIyEmaw 5mr7WzhrZnh0grj3spIZau8xIg3evEtLbR9TUnS+NY8iD8cwRpyJqOZdCeOGuFA7wh4c +brw== X-Gm-Message-State: AOJu0Yw9H5J7UlmimBe6Y9fa6nJBM28bSITd/vy39i0w48pp/Zo/9D/U p3Q9EoaWwNukp3GUrEk1r3+dGI46o5mMm7cOM+nP+L1kUA0PuN4k99LtXBX/hT88YRX0ji8o63C r//MpymVySjCUqOxXQGcRjM4Azqh6ZCNfoAGKWsalHTztvdlT1j0OjowHo1ouWul1g9Ez+a6S+i 5pkOxywQ== X-Received: by 2002:a0c:f087:0:b0:65b:a66:3109 with SMTP id g7-20020a0cf087000000b0065b0a663109mr1345640qvk.8.1695909653104; Thu, 28 Sep 2023 07:00:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrJIlJ1IQOPrf2mY65wDCmu9mIP9xxxmOg4mdtyc+qBEp5ayN5fKBxrbCRmehcWj5nTd7TNQ== X-Received: by 2002:a0c:f087:0:b0:65b:a66:3109 with SMTP id g7-20020a0cf087000000b0065b0a663109mr1345596qvk.8.1695909652659; Thu, 28 Sep 2023 07:00:52 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id n6-20020a0ce486000000b0065cfb75fe81sm1332083qvl.67.2023.09.28.07.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 07:00:52 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 2/5] gdb: use archive name in warning when appropriate Date: Thu, 28 Sep 2023 15:00:41 +0100 Message-Id: <0611bf29b93059df312acf56601cd45398e7dd0e.1695909469.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_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" 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 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). */ From patchwork Thu Sep 28 14:00:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76843 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 3ECF33875DD9 for ; Thu, 28 Sep 2023 14:01:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3ECF33875DD9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695909697; bh=dBzIHnwTBvpk/vvPmoPAM/KsuuxXGY8iF1C1HNFxiqs=; 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=GavhFKHCAqftS2MabrfeKA+dy4yJIrNxTWXA9eBFL4Ce/s/NhmguA3JOJpYowmrMa scOOgSh6quuIKf+SxKwjPs3Lc9mxKVzVLRaZHeGGKuKExAkHCfnVuTm9F7N5Yo45+w GSGdb918pCWky0Z3vPtuvMcTTC2hgBXlrQXZbkUo= 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 33E1B3865C36 for ; Thu, 28 Sep 2023 14:01:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33E1B3865C36 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-448-LFIy6QKDOI2q8MjEugnXSg-1; Thu, 28 Sep 2023 10:01:06 -0400 X-MC-Unique: LFIy6QKDOI2q8MjEugnXSg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-77586b4ae08so21954785a.0 for ; Thu, 28 Sep 2023 07:01:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695909665; x=1696514465; 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=dBzIHnwTBvpk/vvPmoPAM/KsuuxXGY8iF1C1HNFxiqs=; b=Eff1kI5ptpmDNb847VBoKwrKvcnKxC6h7GTrKf1eaiBxUtJLfN+rulaX3C1gLqVuOC N23XXUjR9KKe3nHK0rW4E2vLc4kmmj1DchC9FiYltNnWqLEC8BVZd3KWSAzTzhiJxap3 0OlV3nCifxJCntMmiQnMr2fOgmHjHvTJTIaHuGqBX3mMRNaLpH50yW2D0V9z507EjFIg aYWOo1VBcUMWYdE6ilxOUj4a9akSQ/HXwKOzwLfq02hBVGnu1fvcopvpZKOlIoW+cOAa bPLL4jBgnym/V9OwhiMkeO/W3GsYJZYuWe7MX90N60wN0UkQVI6dcdAXyWymLTYD4bp3 JB8g== X-Gm-Message-State: AOJu0Yxr7ONiuK1fIJKDgkbbeUM0XRpn3FdxR6Dbg7iI1Wrd0/LM7B0i tobJm13G21Zk7r9yeWETbX6SYPh0nLtATLPhibmECc5+7NeCeI2CVZ1R/gXIcBaIrVEdnSSJIKZ xntBUGf4okqZ4wWBswRLgdycquB2nxMsqacXEAp1s8thK2fZvQjNJdYtRlftQXBLsaPwrEs+VUo soxAyXuA== X-Received: by 2002:a05:620a:178e:b0:774:267d:4252 with SMTP id ay14-20020a05620a178e00b00774267d4252mr1272575qkb.15.1695909665032; Thu, 28 Sep 2023 07:01:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGi/zEAezBv7B8OJ02/GkQysnW4VhDnMEEUH9fqhxg76dm4pp80PU9eg0OnZaTS3XZVYjEFfA== X-Received: by 2002:a05:620a:178e:b0:774:267d:4252 with SMTP id ay14-20020a05620a178e00b00774267d4252mr1272508qkb.15.1695909664132; Thu, 28 Sep 2023 07:01:04 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id f12-20020a05620a12ec00b0076eee688a95sm6234112qkl.0.2023.09.28.07.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 07:01:03 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 4/5] gdb: remove print_sys_errmsg Date: Thu, 28 Sep 2023 15:00:43 +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. There were a couple of tests that depended on the existing output message format that needed updating. In one case we gained an extra 'warning: ' prefix, and in the other 'Warning: ' becomes 'warning: ', I think in both cases the new output is an improvement. --- gdb/inflow.c | 3 ++- gdb/main.c | 7 +------ gdb/procfs.c | 17 ++++++++++------- gdb/source.c | 15 ++++----------- gdb/symfile.c | 5 ++--- gdb/testsuite/gdb.base/catch-syscall.exp | 4 ++-- gdb/testsuite/gdb.dwarf2/imported-unit.exp | 2 +- gdb/utils.c | 9 ++++----- gdb/utils.h | 8 +++++++- gdb/windows-nat.c | 2 +- 10 files changed, 34 insertions(+), 38 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/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp index 4a9302fb9b7..0588cb35d87 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.exp +++ b/gdb/testsuite/gdb.base/catch-syscall.exp @@ -392,7 +392,7 @@ proc test_catch_syscall_fail_nodatadir {} { # Make sure GDB doesn't load the syscalls xml from the system # data directory. gdb_test "set data-directory /the/path/to/nowhere" \ - "Warning: /the/path/to/nowhere: .*" + "warning: /the/path/to/nowhere: .*" # Testing to see if we receive a warning when calling "catch # syscall" without XML support (without datadir). @@ -658,7 +658,7 @@ proc do_syscall_tests_without_xml {} { # Make sure GDB doesn't load the syscalls xml from the system data # directory. gdb_test "set data-directory /the/path/to/nowhere" \ - "Warning: /the/path/to/nowhere: .*" + "warning: /the/path/to/nowhere: .*" # Let's test if we can catch syscalls without XML support. # We should succeed, but GDB is not supposed to print syscall names. diff --git a/gdb/testsuite/gdb.dwarf2/imported-unit.exp b/gdb/testsuite/gdb.dwarf2/imported-unit.exp index 7e28931be22..07aa6afbee7 100644 --- a/gdb/testsuite/gdb.dwarf2/imported-unit.exp +++ b/gdb/testsuite/gdb.dwarf2/imported-unit.exp @@ -167,7 +167,7 @@ if { $psymtabs_p } { } gdb_test "l imported_unit.c:1" \ - "1\timported_unit.c: No such file or directory\." + "warning: 1\timported_unit.c: No such file or directory" gdb_test "info source" "\r\nCurrent source file is imported_unit.c\r\n.*" \ "info source for imported_unit.c" 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 Thu Sep 28 14:00:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76845 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 C2C5C386191E for ; Thu, 28 Sep 2023 14:01:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2C5C386191E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695909714; bh=MjGnd4nhTZoatmQJ+MMFC3QIAqD2sh/OC1k74KuLzJs=; 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=gxYisPYZFTnIVOR1UqTr+lyDkePvQnuErDf6SCfLyVJSHnLlYK7T2f83evEf3MCtX YWlWttRn7BTrL6J4gEe63e2GCZt0RisYvBAnopgmZskF3BkwSsT9jsCjcRdCL2tSAv XODQ32A6JqGTA0rwdAg+fzYCHtdGJYadg8mqKqqE= 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 A16D3387103A for ; Thu, 28 Sep 2023 14:01:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A16D3387103A Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-U2SyhenpP7CbSMy3Y_zzYw-1; Thu, 28 Sep 2023 10:01:10 -0400 X-MC-Unique: U2SyhenpP7CbSMy3Y_zzYw-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-41517126c99so214694841cf.2 for ; Thu, 28 Sep 2023 07:01:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695909669; x=1696514469; 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=MjGnd4nhTZoatmQJ+MMFC3QIAqD2sh/OC1k74KuLzJs=; b=F0ldqCvW7dvaqFZv8txhQCQ/ZAejR/1+aEXqJmhMtJ2oTg3szzhkM9K/S9jqMtoc2/ /yFz52hPDtudw3D231XO3M28V0PAF1QeJpq5uQQINycovZ+nN8kO16qpCtHDMElsQCLL aQQGmuU+/q0hQUegJ7082m2+omtJg16x2DMJRtTMKFBQ/q/3FsVG+9UQ1jd6ezsiqYyx RozhSP13n4sOxXsDelzovD5U96So6iVPHnY/DzK0ZOBt+i4evfzLqDUPlRpE9+q3uKtE Q04xrv0Yy/U7DFMCRDTQsTn16YI+3EFxa2OyaARBnF9Yeu5hcdoXuyvpF2v48mIV6iLz oSag== X-Gm-Message-State: AOJu0YxqS9UmJhCCf2+Zkrwx9vvOfwnvZPVdPSo/wAxbFLft+HL5RsO7 O2wahd57FewMw3UFi90gb4zvPo34Du6aWXU2QMP1drNl+uedm+2hOAhXzkG9oHneLJAF2qv/do+ +Z78uetFd4sJmNmqJso2eY4XEEn2ahdjib73xD5s2VG72y24noRXNBas/Z0vpANJkfam8u8aRoA mIIL/HGw== X-Received: by 2002:ac8:7dd6:0:b0:410:acd5:a000 with SMTP id c22-20020ac87dd6000000b00410acd5a000mr1327573qte.21.1695909668062; Thu, 28 Sep 2023 07:01:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/mqwKYw90JXnB07z99noDWT1xetYDBrfQvUDCJ4w7L6FfdD+EhrMgAJksVxWwocuJAr1zGA== X-Received: by 2002:ac8:7dd6:0:b0:410:acd5:a000 with SMTP id c22-20020ac87dd6000000b00410acd5a000mr1327514qte.21.1695909667507; Thu, 28 Sep 2023 07:01:07 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id g28-20020ac84b7c000000b00417fa0cd77esm5180240qts.80.2023.09.28.07.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 07:01:07 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Tom Tromey Subject: [PATCHv2 5/5] gdb: fix reread_symbols when an objfile has target: prefix Date: Thu, 28 Sep 2023 15:00:44 +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, KAM_SHORT, 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" 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 update reread_symbols to use bfd_stat instead of a direct stat call, this adds support for target: files, and fixes the problem. This change was proposed before in this commit: https://inbox.sourceware.org/gdb-patches/20200114210956.25115-3-tromey@adacore.com/ However, that patch never got merged, and seemed to get stuck discussing issues around gnulib stat vs system stat as used by BFD. I didn't 100% understand the issues discussed in that thread, however, I think the problem with the previous thread related to the changes in gdb_bfd.c, rather than to the change in symfile.c. As such, I think this change might be acceptable, my reasoning is: - the objfile::mtime field is set by a call to bfd_get_mtime (see objfiles.c), which calls bfd_stat under the hood. This will end up using the system stat, - In symfile.c we currently call stat directly, which will call the gnulib stat, which, if I understand the above thread correctly, might give a different result to the system stat in some cases, - By switching to using bfd_stat in symfile.c we should now be consistently calling the system stat, Co-Authored-By: Tom Tromey --- gdb/symfile.c | 18 +- gdb/testsuite/gdb.server/target-exec-file.c | 22 +++ gdb/testsuite/gdb.server/target-exec-file.exp | 174 ++++++++++++++++++ 3 files changed, 203 insertions(+), 11 deletions(-) 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..87f8e0a3ea6 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2470,19 +2470,15 @@ reread_symbols (int from_tty) if (objfile->separate_debug_objfile_backlink) continue; - /* If this object is from an archive (what you usually create with - `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) - filename = bfd_get_filename (objfile->obfd->my_archive); - else - filename = objfile_name (objfile); - - int res = stat (filename, &new_statbuf); + int res = bfd_stat (objfile->obfd.get (), &new_statbuf); if (res != 0) { + const char *filename; + if (objfile->obfd->my_archive) + filename = bfd_get_filename (objfile->obfd->my_archive); + else + filename = objfile_name (objfile); + warning (_("`%ps' has disappeared; keeping its symbols."), styled_string (file_name_style.style (), filename)); continue; 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