This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [PATCH 07/10] btrace, linux: Enable ptwrite packets.
- From: "Metzger, Markus T" <markus dot t dot metzger at intel dot com>
- To: "Willgerodt, Felix" <felix dot willgerodt at intel dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Tue, 4 Jun 2019 12:36:25 +0000
- Subject: RE: [PATCH 07/10] btrace, linux: Enable ptwrite packets.
- References: <1559119673-30516-1-git-send-email-felix.willgerodt@intel.com> <1559119673-30516-8-git-send-email-felix.willgerodt@intel.com>
Hello Felix,
> diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
> index ef291ec2310..6eb5334e0ae 100644
> --- a/gdb/nat/linux-btrace.c
> +++ b/gdb/nat/linux-btrace.c
> @@ -32,6 +32,10 @@
>
> #include <sys/syscall.h>
>
> +#if defined (HAVE_LIBIPT)
> +#include <intel-pt.h>
> +#endif
This code is used for gdbserver, as well, which doesn't link against libipt.so. Also, we don't
seem to be using anything from that header - and we shouldn't.
> +
> #if HAVE_LINUX_PERF_EVENT_H && defined(SYS_perf_event_open)
> #include <unistd.h>
> #include <sys/mman.h>
> @@ -409,6 +413,31 @@ cpu_supports_bts (void)
> }
> }
>
> +#if defined (PERF_ATTR_SIZE_VER5)
This guard shouldn't be needed. We're not using anything from struct perf_event_attr here.
> +/* Check whether the linux target supports Intel Processor Trace PTWRITE. */
> +
> +static bool
> +linux_supports_ptwrite ()
> +{
> + static const char filename[]
> + = "/sys/bus/event_source/devices/intel_pt/caps/ptwrite";
> + gdb_file_up file = gdb_fopen_cloexec (filename, "r");
> +
> + if (file.get () == nullptr)
> + return false;
> +
> + int status, found = fscanf (file.get (), "%d", &status);
> +
> + if (found != 1)
> + {
> + warning (_("Failed to determine ptwrite support from %s."), filename);
> + return false;
> + }
> +
> + return status == 1;
> +}
> +#endif /* defined (PERF_ATTR_SIZE_VER5) */
> +
> /* The perf_event_open syscall failed. Try to print a helpful error
> message. */
>
> @@ -601,6 +630,9 @@ linux_enable_pt (ptid_t ptid, const struct
> btrace_config_pt *conf)
> pt->attr.exclude_hv = 1;
> pt->attr.exclude_idle = 1;
>
> + if (linux_supports_ptwrite ())
> + pt->attr.config |= 0x1000;
Doing this unconditionally may break GDBs that have been built with an old libipt that
doesn't support the PTW packet.
We should probably have GDB request PTW via CONF. This may need extending RSP.
> +
> errno = 0;
> scoped_fd fd (syscall (SYS_perf_event_open, &pt->attr, pid, -1, -1, 0));
> if (fd.get () < 0)
> --
> 2.20.1
Thanks,
Markus.
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928