* [PATCH] gdb, btrace: improve error messages
@ 2022-02-01 12:10 Markus Metzger
2022-02-01 14:17 ` Simon Marchi
0 siblings, 1 reply; 2+ messages in thread
From: Markus Metzger @ 2022-02-01 12:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Sobisch
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 <simonsobisch@gnu.org>
---
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)
--
2.34.1
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gdb, btrace: improve error messages
2022-02-01 12:10 [PATCH] gdb, btrace: improve error messages Markus Metzger
@ 2022-02-01 14:17 ` Simon Marchi
0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2022-02-01 14:17 UTC (permalink / raw)
To: Markus Metzger, gdb-patches; +Cc: Simon Sobisch
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 <simonsobisch@gnu.org>
> ---
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-01 14:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 12:10 [PATCH] gdb, btrace: improve error messages Markus Metzger
2022-02-01 14:17 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).