public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Metzger, Markus T" <markus.t.metzger@intel.com>
To: "Willgerodt, Felix" <felix.willgerodt@intel.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH 07/10] btrace, linux: Enable ptwrite packets.
Date: Tue, 04 Jun 2019 12:36:00 -0000	[thread overview]
Message-ID: <A78C989F6D9628469189715575E55B236B43FD37@IRSMSX104.ger.corp.intel.com> (raw)
In-Reply-To: <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

  reply	other threads:[~2019-06-04 12:36 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29  8:48 [PATCH 00/10] Extensions for PTWRITE felix.willgerodt
2019-05-29  8:48 ` [PATCH 02/10] btrace: Enable auxiliary instructions in record instruction-history felix.willgerodt
2019-06-04 12:35   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 05/10] python: Introduce gdb.RecordAuxiliary class felix.willgerodt
2019-05-29 14:42   ` Eli Zaretskii
2019-06-04 12:36   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 10/10] btrace: Extend event decoding for ptwrite felix.willgerodt
2019-05-29 14:53   ` Eli Zaretskii
2019-06-04 12:37   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 01/10] btrace: Introduce auxiliary instructions felix.willgerodt
2019-05-29 14:39   ` Eli Zaretskii
2019-06-04 12:35   ` Metzger, Markus T
2019-05-29  8:48 ` [PATCH 04/10] btrace: Handle stepping and goto for " felix.willgerodt
2019-06-04 12:35   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 06/10] python: Add clear_trace() to gdb.Record felix.willgerodt
2019-05-29 14:41   ` Eli Zaretskii
2019-06-04 12:36   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 07/10] btrace, linux: Enable ptwrite packets felix.willgerodt
2019-06-04 12:36   ` Metzger, Markus T [this message]
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 08/10] btrace, python: Enable ptwrite listener registration felix.willgerodt
2019-06-04 12:36   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2019-05-29  8:48 ` [PATCH 03/10] btrace: Enable auxiliary instructions in record function-call-history felix.willgerodt
2019-05-29 14:40   ` Eli Zaretskii
2019-06-04 12:35   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix
2021-06-16  9:13       ` Metzger, Markus T
2021-06-16 10:03         ` Willgerodt, Felix
2021-06-16 10:16           ` Metzger, Markus T
2019-05-29  8:48 ` [PATCH 09/10] btrace, python: Enable calling the ptwrite listener felix.willgerodt
2019-06-04 12:37   ` Metzger, Markus T
2021-06-14 14:53     ` Willgerodt, Felix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=A78C989F6D9628469189715575E55B236B43FD37@IRSMSX104.ger.corp.intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=felix.willgerodt@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).