This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [PATCH 07/10] btrace, linux: Enable ptwrite packets.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]