Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: "Jose E. Marchesi" <jose.marchesi@oracle.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH V2 6/9] Support for DTrace USDT probes in x86_64 targets.
Date: Thu, 16 Oct 2014 22:07:00 -0000	[thread overview]
Message-ID: <544041B1.7060908@redhat.com> (raw)
In-Reply-To: <1412961772-16249-7-git-send-email-jose.marchesi@oracle.com>

> +amd64_dtrace_probe_is_enabled (struct gdbarch *gdbarch, CORE_ADDR addr)
> +{
> +  gdb_byte buf[5];
> +  read_memory (addr - 3, buf, 5);
> +
> +  /* The instruction sequence used in x86_64 machines for a disabled
> +     is-enabled probe is:
> +
> +              xor %rax, %rax  =>  48 33 C0
> +     ADDR:    nop             =>  90
> +              nop             =>  90
> +

Please use read_code when reading code, so that these reads go through
the code cache.

> +  /* We use the following instruction sequence for disabling an
> +     is-enabled probe:
> +
> +     xor %rax, %rax; nop; nop  =>  48 33 C0 90 90
> +
> +     Note that ADDR is offset 3 bytes from the beginning of the
> +     sequence.  */
> +
> +  gdb_byte buf[5];
> +
> +  buf[0] = 0x48;
> +  buf[1] = 0x33;
> +  buf[2] = 0xc0;
> +  buf[3] = 0x90;
> +  buf[4] = 0x90;
> +  
> +  write_memory (addr - 3, buf, 5);

These code sequences are duplicated in lots of places.

Writing like this instead is both shorter and less error prone:

   const gdb_byte buf[] = { 0x48, 0x33, 0xc0, 0x90, 0x90 };

   write_memory (addr - 3, buf, sizeof (buf));

... and IMO eliminates the need to have the sequence duplicated in the
comment above.

Going further, we can make these sequences be globals, like:

  /* The instruction sequences used in x86_64 machines for a
     disabled is-enabled probe.  */
   const gdb_byte amd64_dtrace_disabled_probe_sequence_1[] = {
     /*          xor %rax, %rax */  0x48, 0x33, 0xc0,
     /* ADDR:    nop            */  0x90,
     /*          nop            */  0x90
   };
   const gdb_byte amd64_dtrace_disabled_probe_sequence_2[] = {
     /*          xor %rax, %rax */  0x48, 0x33, 0xc0,
     /* ADDR:    ret            */  0xc3,
     /*          nop            */  0x90
   };

etc.  And then instead of:

> +amd64_dtrace_probe_is_enabled (struct gdbarch *gdbarch, CORE_ADDR addr)
> +{
> +  gdb_byte buf[5];
> +  read_memory (addr - 3, buf, 5);
> +
> +  /* The instruction sequence used in x86_64 machines for a disabled
> +     is-enabled probe is:
> +
> +              xor %rax, %rax  =>  48 33 C0
> +     ADDR:    nop             =>  90
> +              nop             =>  90
> +
> +     or
> +
> +              xor %rax, %rax  =>  48 33 C0
> +     ADDR:    ret             =>  c3
> +              nop             =>  90
> +
> +     This function returns 1 if the instructions at ADDR do _not_
> +     follow any of these patterns.
> +
> +     Note that ADDR is offset 3 bytes from the beginning of these
> +     sequences.  */
> +
> +  return !((buf[0] == 0x48) && (buf[1] == 0x33) && (buf[2] == 0xc0) /* xor */
> +	   && ((buf[3] == 0x90) || (buf[3] == 0xc3))                /* nop | ret */
> +	   && (buf[4] == 0x90));                                    /* nop */
> +}

Simply write:

amd64_dtrace_probe_is_enabled (struct gdbarch *gdbarch, CORE_ADDR addr)
{
   gdb_byte buf[5];
   read_code (addr - 3, buf, 5);

   return (memcmp (buf, amd64_dtrace_disabled_probe_sequence_1) != 0
           && memcmp (buf, amd64_dtrace_disabled_probe_sequence_2) != 0)
}

... etc.

Let the compiler worry about optimizing those memcmps if necessary.


> +  static int arg_reg_map[6] =

write:

  static const int arg_reg_map[] =


> +    {
> +      AMD64_RDI_REGNUM,  /* Arg 1.  */
> +      AMD64_RSI_REGNUM,  /* Arg 2.  */
> +      AMD64_RDX_REGNUM,  /* Arg 3.  */
> +      AMD64_RCX_REGNUM,  /* Arg 4.  */
> +      AMD64_R8_REGNUM,   /* Arg 5.  */
> +      AMD64_R9_REGNUM    /* Arg 6.  */
> +    };
+
+  /* DTrace probe arguments can be found on the ABI-defined places for
+     regular arguments at the current PC.  The probe abstraction
+     currently supports up to 12 arguments for probes.  */
+
+  if (narg < 6)
+    {

I'd suggest putting the arg_reg_map array within this if block.

Thanks,
Pedro Alves


  reply	other threads:[~2014-10-16 22:07 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 17:18 [PATCH V2 0/9] Add support for DTrace USDT probes to gdb Jose E. Marchesi
2014-10-10 17:18 ` [PATCH V2 3/9] New commands `enable probe' and `disable probe' Jose E. Marchesi
2014-10-10 18:15   ` Eli Zaretskii
2014-10-10 22:03   ` Doug Evans
2014-10-11  6:35     ` Jose E. Marchesi
2014-10-13 16:41       ` Doug Evans
2014-10-14 19:02         ` Sergio Durigan Junior
2014-10-17  0:07           ` Doug Evans
2014-10-17  0:36       ` Pedro Alves
2014-10-17  0:43         ` Pedro Alves
2014-10-17  2:31           ` Sergio Durigan Junior
2014-10-17 11:23             ` Pedro Alves
2014-10-17  0:55         ` Sergio Durigan Junior
2014-10-17  5:52           ` Jose E. Marchesi
2014-10-11 17:04     ` Sergio Durigan Junior
2014-10-14 18:53   ` Sergio Durigan Junior
2014-10-15 13:28     ` Jose E. Marchesi
2014-10-10 17:18 ` [PATCH V2 9/9] Announce the DTrace USDT probes support in NEWS Jose E. Marchesi
2014-10-10 18:16   ` Eli Zaretskii
2014-10-10 17:18 ` [PATCH V2 7/9] Simple testsuite for DTrace USDT probes Jose E. Marchesi
2014-10-16 22:36   ` Pedro Alves
2014-10-17 12:01     ` Jose E. Marchesi
2014-10-17 12:18       ` Pedro Alves
2014-10-10 17:18 ` [PATCH V2 1/9] Adapt `info probes' to support printing probes of different types Jose E. Marchesi
2014-10-10 17:18 ` [PATCH V2 5/9] New probe type: DTrace USDT probes Jose E. Marchesi
2014-10-14 19:01   ` Sergio Durigan Junior
2014-10-15 13:28     ` Jose E. Marchesi
2014-10-10 17:18 ` [PATCH V2 6/9] Support for DTrace USDT probes in x86_64 targets Jose E. Marchesi
2014-10-16 22:07   ` Pedro Alves [this message]
2014-10-16 22:07   ` Pedro Alves
2014-10-17 12:35     ` Jose E. Marchesi
2014-10-17 12:42       ` Pedro Alves
2014-10-17 12:47         ` Jose E. Marchesi
2014-10-17 12:53           ` Pedro Alves
2014-10-17 19:48             ` Jose E. Marchesi
2014-10-16 22:17   ` Pedro Alves
2014-10-10 17:18 ` [PATCH V2 4/9] New gdbarch functions: dtrace_parse_probe_argument, dtrace_probe_is_enabled, dtrace_enable_probe, dtrace_disable_probe Jose E. Marchesi
2014-10-10 17:18 ` [PATCH V2 2/9] Move `compute_probe_arg' and `compile_probe_arg' to probe.c Jose E. Marchesi
2014-10-10 17:18 ` [PATCH V2 8/9] Documentation for DTrace USDT probes Jose E. Marchesi
2014-10-10 18:18   ` Eli Zaretskii

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=544041B1.7060908@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jose.marchesi@oracle.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