Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: markus.t.metzger@intel.com
Cc: gdb-patches@sourceware.org, markus.t.metzger@gmail.com,
	       jan.kratochvil@redhat.com, palves@redhat.com,
	tromey@redhat.com,        kettenis@gnu.org
Subject: Re: [patch v4 08/13] remote, btrace: add branch trace remote ops
Date: Wed, 28 Nov 2012 19:23:00 -0000	[thread overview]
Message-ID: <50B664AE.1020006@redhat.com> (raw)
In-Reply-To: <1354013351-14791-9-git-send-email-markus.t.metzger@intel.com>

New packets always need documentation.  And NEWS entries too.
The new "set remote XXX" commands need docs too.

On 11/27/2012 10:49 AM, markus.t.metzger@intel.com wrote:
> From: Markus Metzger <markus.t.metzger@intel.com>
> 
> Add the gdb remote target operations for branch tracing. We define the following
> packets:
> 
>   qbtrace:<ptid>  query if new trace data is available for a thread
>                   returns "yes" or "no" or "Enn"

The code isn't handling "no".

> 
>   Qbtrace:on:<ptid>  enable branch tracing for one thread
>                      returns "OK" or "Enn"
> 
>   Qbtrace:off:<ptid>  disable branch tracing for one thread
>                       returns "OK" or "Enn"

Nit,  I'd put <ptid> first:

>   Qbtrace:<ptid>:on  enable branch tracing for one thread
>                      returns "OK" or "Enn"
>
>   Qbtrace:<ptid>:off  disable branch tracing for one thread
>                       returns "OK" or "Enn"


How does "btrace enable all" for new threads work with remote targets?
GDB isn't notified of new threads until they stop for some reason.

> 
>   qXfer:btrace:read:<ptid>   read the full branch trace data for one thread

No need to pass the thread in the annex.  qXfer packets use the general
context set by remote_xfer_partial -> set_current_thread.

> 	(_initialize_remote): Add btrace packets.

Say:

        (_initialize_remote): Add packet configuration for
        branch tracing.

> diff --git a/gdb/remote.c b/gdb/remote.c
> index 929d4f5..c512b93 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -67,6 +67,7 @@
>  #include "ax.h"
>  #include "ax-gdb.h"
>  #include "agent.h"
> +#include "btrace.h"

Should be mentioned on the change log too.

>  
>  /* Temp hacks for tracepoint encoding migration.  */
>  static char *target_buf;
> @@ -1292,6 +1293,9 @@ enum {
>    PACKET_qXfer_fdpic,
>    PACKET_QDisableRandomization,
>    PACKET_QAgent,
> +  PACKET_qbtrace,
> +  PACKET_Qbtrace,
> +  PACKET_qXfer_btrace,
>    PACKET_MAX
>  };
>  
> @@ -3946,6 +3950,10 @@ static struct protocol_feature remote_protocol_features[] = {
>    { "QAgent", PACKET_DISABLE, remote_supported_packet, PACKET_QAgent},
>    { "tracenz", PACKET_DISABLE,
>      remote_string_tracing_feature, -1 },
> +  { "qbtrace", PACKET_DISABLE, remote_supported_packet, PACKET_qbtrace },
> +  { "Qbtrace", PACKET_DISABLE, remote_supported_packet, PACKET_Qbtrace },
> +  { "qXfer:btrace:read", PACKET_DISABLE, remote_supported_packet,
> +    PACKET_qXfer_btrace }
>  };
>  
>  static char *remote_support_xml;
> @@ -8682,6 +8690,10 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
>        return remote_read_qxfer (ops, "uib", annex, readbuf, offset, len,
>  				&remote_protocol_packets[PACKET_qXfer_uib]);
>  
> +    case TARGET_OBJECT_BTRACE:
> +      return remote_read_qxfer (ops, "btrace", annex, readbuf, offset, len,
> +        &remote_protocol_packets[PACKET_qXfer_btrace]);
> +
>      default:
>        return -1;
>      }
> @@ -11001,6 +11013,137 @@ remote_can_use_agent (void)
>    return (remote_protocol_packets[PACKET_QAgent].support != PACKET_DISABLE);
>  }
>  
> +struct btrace_target_info
> +{
> +  /* The ptid of the traced thread.  */
> +  ptid_t ptid;
> +};

Hmm, why would you need to store this?  To get at a struct btrace_target_info,
you need to start from a struct thread_info, so why not just pass that
down, or pass the ptid down?

> +
> +/* Check whether the target supports branch tracing.  */
> +static int
> +remote_supports_btrace (void)
> +{
> +  if (remote_protocol_packets[PACKET_qbtrace].support != PACKET_ENABLE)
> +    return 0;
> +  if (remote_protocol_packets[PACKET_Qbtrace].support != PACKET_ENABLE)
> +    return 0;
> +  if (remote_protocol_packets[PACKET_qXfer_btrace].support != PACKET_ENABLE)
> +    return 0;
> +
> +  return 1;
> +}
> +
> +/* Enable branch tracing for @ptid.  */
> +static struct btrace_target_info *
> +remote_enable_btrace (ptid_t ptid)
> +{
> +  struct packet_config *packet = &remote_protocol_packets[PACKET_Qbtrace];
> +  struct remote_state *rs = get_remote_state ();
> +  struct btrace_target_info *tinfo = NULL;
> +  char *buf = rs->buf;
> +  char *endbuf = rs->buf + get_remote_packet_size ();
> +
> +  if (packet->support != PACKET_ENABLE)
> +    error (_("Target does not support branch tracing."));
> +
> +  buf += xsnprintf (buf, endbuf - buf, "%s", packet->name);
> +  buf += xsnprintf (buf, endbuf - buf, ":on:");
> +  buf = write_ptid (buf, endbuf, ptid);
> +  putpkt (rs->buf);
> +  getpkt (&rs->buf, &rs->buf_size, 0);
> +
> +  if (packet_ok (rs->buf, packet) != PACKET_OK)
> +    error (_("Could not enable branch tracing for %s."),
> +           target_pid_to_str (ptid));
> +
> +  tinfo = xzalloc (sizeof (*tinfo));
> +  tinfo->ptid = ptid;
> +
> +  return tinfo;
> +}
> +
> +/* Disable branch tracing.  */
> +static void
> +remote_disable_btrace (struct btrace_target_info *tinfo)
> +{
> +  struct packet_config *packet = &remote_protocol_packets[PACKET_Qbtrace];
> +  struct remote_state *rs = get_remote_state ();
> +  char *buf = rs->buf;
> +  char *endbuf = rs->buf + get_remote_packet_size ();
> +
> +  if (packet->support != PACKET_ENABLE)
> +    error (_("Target does not support branch tracing."));
> +
> +  buf += xsnprintf (buf, endbuf - buf, "%s", packet->name);
> +  buf += xsnprintf (buf, endbuf - buf, ":off:");
> +  buf = write_ptid (buf, endbuf, tinfo->ptid);
> +  putpkt (rs->buf);
> +  getpkt (&rs->buf, &rs->buf_size, 0);
> +
> +  if (packet_ok (rs->buf, packet) != PACKET_OK)
> +    error (_("Could not disable branch tracing for %s."),
> +           target_pid_to_str (tinfo->ptid));
> +
> +  xfree (tinfo);
> +}

remote_enable_btrace/remote_disable_btrace are almost identical.
You could factor this out to a function that takes a on/off boolean.


-- 
Pedro Alves


  reply	other threads:[~2012-11-28 19:23 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-27 10:50 [patch v4 00/13] branch tracing support for Atom markus.t.metzger
2012-11-27 10:49 ` [patch v4 03/13] cli, btrace: add btrace cli markus.t.metzger
2012-11-27 21:53   ` Tom Tromey
2012-11-30 15:09     ` Metzger, Markus T
2012-11-30 15:16       ` Jan Kratochvil
2012-11-30 15:23         ` Metzger, Markus T
2012-11-27 10:49 ` [patch v4 01/13] disas: add precise instructions flag markus.t.metzger
2012-11-27 16:49   ` Pedro Alves
2012-11-27 16:52     ` Jan Kratochvil
2012-11-27 16:56       ` Pedro Alves
2012-11-27 17:26     ` Metzger, Markus T
2012-11-27 17:33       ` Pedro Alves
2012-11-28 14:44         ` Metzger, Markus T
2012-11-27 10:50 ` [patch v4 07/13] xml, btrace: define btrace xml document style markus.t.metzger
2012-11-28 18:53   ` Pedro Alves
2012-12-04 10:35     ` Metzger, Markus T
2012-11-27 10:50 ` [patch v4 04/13] configure: add check for perf_event header markus.t.metzger
2012-11-28 10:11   ` Pedro Alves
2012-11-28 14:52     ` Metzger, Markus T
2012-11-28 14:55       ` Pedro Alves
2012-11-27 10:50 ` [patch v4 12/13] test, btrace: more branch tracing tests markus.t.metzger
2012-11-27 10:50 ` [patch v4 10/13] gdbserver, linux, btrace: add btrace support for linux-low markus.t.metzger
2012-11-28 20:44   ` Pedro Alves
2012-12-05  9:27     ` Metzger, Markus T
2012-11-27 10:50 ` [patch v4 05/13] linux, btrace: perf_event based branch tracing markus.t.metzger
2012-11-28 17:31   ` Pedro Alves
2012-12-03 14:38     ` Metzger, Markus T
2012-11-27 10:50 ` [patch v4 09/13] gdbserver, btrace: add generic btrace support markus.t.metzger
2012-11-28 20:32   ` Pedro Alves
2012-12-04 14:50     ` Metzger, Markus T
2012-11-27 10:50 ` [patch v4 11/13] test, btrace: add branch tracing tests markus.t.metzger
2012-11-27 10:50 ` [patch v4 02/13] thread, btrace: add generic branch trace support markus.t.metzger
2012-11-27 18:32   ` Pedro Alves
2012-11-27 18:38     ` Pedro Alves
2012-11-28  0:41       ` Pedro Alves
2012-11-29 16:39     ` Metzger, Markus T
2012-11-27 10:50 ` [patch v4 06/13] linux, i386, amd64: enable btrace for 32bit and 64bit linux native markus.t.metzger
2012-11-28 18:40   ` Pedro Alves
2012-12-03 16:24     ` Metzger, Markus T
2012-11-27 10:50 ` [patch v4 08/13] remote, btrace: add branch trace remote ops markus.t.metzger
2012-11-28 19:23   ` Pedro Alves [this message]
2012-12-04 12:47     ` Metzger, Markus T
2012-11-27 10:50 ` [patch v4 13/13] btrace, x86: restrict to Atom markus.t.metzger
2012-11-27 11:19   ` Mark Kettenis
2012-11-27 11:49     ` Metzger, Markus T
2012-11-27 14:42       ` Mark Kettenis
2012-11-27 15:14         ` Metzger, Markus T
2012-11-27 15:32           ` Pedro Alves
2012-11-27 13:05   ` Jan Kratochvil
2012-11-27 14:04     ` Metzger, Markus T
2012-11-27 14:29       ` Jan Kratochvil
2012-11-27 15:14         ` Metzger, Markus T
2012-11-27 15:50           ` Pedro Alves
2012-11-27 15:54             ` Metzger, Markus T
2012-12-06 10:15         ` Metzger, Markus T
2012-11-27 13:11 ` [patch v4 00/13] branch tracing support for Atom Jan Kratochvil
2012-11-27 14:26   ` Metzger, Markus T
2012-11-27 14:32     ` Jan Kratochvil
2012-11-27 14:40       ` Metzger, Markus T
2012-11-27 15:36       ` Jan Kratochvil
2012-11-27 16:17         ` Metzger, Markus T
2012-11-27 16:28           ` Jan Kratochvil
2012-11-27 17:30             ` Metzger, Markus T
2012-11-27 18:31               ` Jan Kratochvil
2012-11-27 18:56                 ` Markus Metzger
2012-11-28 19:01                   ` Jan Kratochvil
2012-11-29  9:13                     ` Metzger, Markus T

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=50B664AE.1020006@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=kettenis@gnu.org \
    --cc=markus.t.metzger@gmail.com \
    --cc=markus.t.metzger@intel.com \
    --cc=tromey@redhat.com \
    /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