Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: Ian Lance Taylor <iant@google.com>
Cc: Doug Evans <dje@google.com>, Stan Shebs <stan@codesourcery.com>,
	gdb-patches@sourceware.org, Eli Zaretskii <eliz@gnu.org>,
	tromey@redhat.com
Subject: Re: [NEWS/RFA] Re: [gdbserver] x86 agent expression bytecode compiler  (speed up conditional tracepoints)
Date: Sun, 20 Jun 2010 22:27:00 -0000	[thread overview]
Message-ID: <201006202326.44538.pedro@codesourcery.com> (raw)
In-Reply-To: <mcr4oh234zj.fsf@dhcp-172-17-9-151.mtv.corp.google.com>

On Thursday 17 June 2010 00:57:52, Ian Lance Taylor wrote:
> Doug Evans <dje@google.com> writes:
> 
> > This worked with the gcc4.4.0 variant I was using.
> >
> > Ian: Is there a Right way to do this?
> 
> I don't know about a right way, but since this code is both gcc and
> x86 specific, I think I would just write something along the lines of
> 
> #define EMIT_ASM(NAME, INSNS) \
>   do \
>    { \
>      extern unsigned char start_ ## NAME, end_ ## NAME; \
>      add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME); \
>      asm ("jmp end_" NAME "\; start_" NAME ":\;" INSNS "\; end_" NAME ":"); \
>    } while (0)

Thanks, works, nice and simple.  I've applied the patch below.

-- 
Pedro Alves

2010-06-20  Ian Lance Taylor  <iant@google.com>
	    Pedro Alves  <pedro@codesourcery.com>

	* linux-x86-low.c (always_true): Delete.
	(EMIT_ASM, EMIT_ASM32): Use an uncondition asm jmp instead of
	trying to fool the compiler with always_true.

---
 gdb/gdbserver/linux-x86-low.c |   46 +++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

Index: src/gdb/gdbserver/linux-x86-low.c
===================================================================
--- src.orig/gdb/gdbserver/linux-x86-low.c	2010-06-20 22:43:08.000000000 +0100
+++ src/gdb/gdbserver/linux-x86-low.c	2010-06-20 22:59:05.000000000 +0100
@@ -1484,41 +1484,37 @@ add_insns (unsigned char *start, int len
   current_insn_ptr = buildaddr;
 }
 
-/* A function used to trick optimizers.  */
-
-int
-always_true (void)
-{
-  return 1;
-}
-
 /* Our general strategy for emitting code is to avoid specifying raw
    bytes whenever possible, and instead copy a block of inline asm
    that is embedded in the function.  This is a little messy, because
    we need to keep the compiler from discarding what looks like dead
    code, plus suppress various warnings.  */
 
-#define EMIT_ASM(NAME,INSNS)						\
-  { extern unsigned char start_ ## NAME, end_ ## NAME;			\
-    add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME);	\
-    if (always_true ())						\
-      goto skipover ## NAME;						\
-    __asm__ ("start_" #NAME ":\n\t" INSNS "\n\tend_" #NAME ":\n\t");	\
-    skipover ## NAME:							\
-    ; }
-
+#define EMIT_ASM(NAME, INSNS)						\
+  do									\
+    {									\
+      extern unsigned char start_ ## NAME, end_ ## NAME;		\
+      add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME);	\
+      __asm__ ("jmp end_" #NAME "\n"				\
+	       "\t" "start_" #NAME ":"					\
+	       "\t" INSNS "\n"						\
+	       "\t" "end_" #NAME ":");					\
+    } while (0)
 
 #ifdef __x86_64__
 
 #define EMIT_ASM32(NAME,INSNS)						\
-  { extern unsigned char start_ ## NAME, end_ ## NAME;			\
-    add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME);	\
-    if (always_true ())						\
-      goto skipover ## NAME;						\
-    __asm__ (".code32\n\tstart_" #NAME ":\n\t" INSNS "\n\tend_" #NAME ":\n" \
-	     "\t.code64\n\t");						\
-    skipover ## NAME:							\
-    ; }
+  do									\
+    {									\
+      extern unsigned char start_ ## NAME, end_ ## NAME;		\
+      add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME);	\
+      __asm__ (".code32\n"						\
+	       "\t" "jmp end_" #NAME "\n"				\
+	       "\t" "start_" #NAME ":\n"				\
+	       "\t" INSNS "\n"						\
+	       "\t" "end_" #NAME ":\n"					\
+	       ".code64\n");						\
+    } while (0)
 
 #else
 


  reply	other threads:[~2010-06-20 22:27 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-07 16:00 Pedro Alves
2010-06-07 16:04 ` Michael Snyder
2010-06-07 16:35   ` Joel Brobecker
2010-06-10 17:28 ` Tom Tromey
2010-06-10 17:36   ` Pedro Alves
2010-06-10 18:43     ` Tom Tromey
2010-06-14 11:15       ` [NEWS/RFA] " Pedro Alves
2010-06-14 17:29         ` Eli Zaretskii
2010-06-14 22:19           ` Pedro Alves
2010-06-16 18:57             ` Doug Evans
2010-06-16 19:13               ` Stan Shebs
2010-06-16 19:16                 ` Pedro Alves
2010-06-16 19:21                   ` Doug Evans
2010-06-16 23:58                     ` Ian Lance Taylor
2010-06-20 22:27                       ` Pedro Alves [this message]
2010-06-16 19:31                   ` Stan Shebs
2010-06-17 18:03                     ` Michael Snyder
2010-06-19 16:13                       ` Hui Zhu
2010-06-19 16:16                         ` Doug Evans
2010-06-19 17:13                           ` Hui Zhu
2010-06-19 17:26                             ` Doug Evans
2010-06-20  9:30                               ` [RFA-new version][gdbserver] " Pierre Muller
     [not found]                               ` <-3945058798826177264@unknownmsgid>
2010-06-20 15:30                                 ` Doug Evans
2010-06-20 17:02                                   ` Pierre Muller
     [not found]                                   ` <-1673004315710326113@unknownmsgid>
2010-06-20 17:11                                     ` Doug Evans
2010-06-20 18:41                                   ` Tom Tromey
2010-06-20 20:36                                     ` Pierre Muller
2010-06-20 21:07                                       ` Pierre Muller
2010-06-21  1:47                                         ` Tom Tromey
2010-06-21  6:31                                           ` Pierre Muller
2010-06-20 18:31                         ` [NEWS/RFA] Re: [gdbserver] " Tom Tromey

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=201006202326.44538.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=dje@google.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=iant@google.com \
    --cc=stan@codesourcery.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