From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 56FB2385B80B for ; Tue, 1 Feb 2022 14:17:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 56FB2385B80B Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 211EHCgP004011 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 1 Feb 2022 09:17:17 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 211EHCgP004011 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8FBB51EA69; Tue, 1 Feb 2022 09:17:11 -0500 (EST) Message-ID: Date: Tue, 1 Feb 2022 09:17:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] gdb, btrace: improve error messages Content-Language: en-US To: Markus Metzger , gdb-patches@sourceware.org Cc: Simon Sobisch References: <20220201121046.2160219-1-markus.t.metzger@intel.com> From: Simon Marchi In-Reply-To: <20220201121046.2160219-1-markus.t.metzger@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 1 Feb 2022 14:17:12 +0000 X-Spam-Status: No, score=-3039.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2022 14:17:22 -0000 On 2022-02-01 07:10, Markus Metzger via Gdb-patches wrote: > When trying to use 'record btrace' on a system that does not support it, > the error message isn't as clear as it could be. See > https://sourceware.org/pipermail/gdb/2022-January/049870.html. > > Improve the error message in a few cases. > > Reported-by: Simon Sobisch > --- > gdb/nat/linux-btrace.c | 17 +++++++++++++++-- > 1 file changed, 15 insertions(+), 2 deletions(-) > > diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c > index d8880756aad..13ed493495d 100644 > --- a/gdb/nat/linux-btrace.c > +++ b/gdb/nat/linux-btrace.c > @@ -429,7 +429,7 @@ diagnose_perf_event_open_fail () > static const char filename[] = "/proc/sys/kernel/perf_event_paranoid"; > gdb_file_up file = gdb_fopen_cloexec (filename, "r"); > if (file.get () == nullptr) > - break; > + error (_("Your system does not support process recording.")); > > int level, found = fscanf (file.get (), "%d", &level); > if (found == 1 && level > 2) > @@ -571,7 +571,20 @@ perf_event_pt_event_type () > errno = 0; > gdb_file_up file = gdb_fopen_cloexec (filename, "r"); > if (file.get () == nullptr) > - error (_("Failed to open %s: %s."), filename, safe_strerror (errno)); > + switch (errno) > + { > + case EACCES: > + case EFAULT: > + case EPERM: > + error (_("You do not have permission to use Intel PT.")); > + > + case ENOTDIR: > + case ENOENT: > + error (_("Your system does not support Intel PT.")); > + > + default: > + error (_("Failed to open %s: %s."), filename, safe_strerror (errno)); > + } > > int type, found = fscanf (file.get (), "%d", &type); > if (found != 1) I think the more detailed messages are nice. But I would still mention the underlying error, to indicate how GDB reached that conclusion. That gives the user has something to grab onto to understand and fix the problem. For example: Failed to open %s (%s). You do not have permission to use Intel PT. where the %s are respectively the filename and the strerror. Simon