From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29584 invoked by alias); 20 Jun 2010 22:27:03 -0000 Received: (qmail 29568 invoked by uid 22791); 20 Jun 2010 22:27:02 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 20 Jun 2010 22:26:58 +0000 Received: (qmail 7837 invoked from network); 20 Jun 2010 22:26:51 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 20 Jun 2010 22:26:51 -0000 From: Pedro Alves To: Ian Lance Taylor Subject: Re: [NEWS/RFA] Re: [gdbserver] x86 agent expression bytecode compiler (speed up conditional tracepoints) Date: Sun, 20 Jun 2010 22:27:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.31-10-rt; KDE/4.4.2; x86_64; ; ) Cc: Doug Evans , Stan Shebs , gdb-patches@sourceware.org, Eli Zaretskii , tromey@redhat.com References: <201006071700.28706.pedro@codesourcery.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201006202326.44538.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-06/txt/msg00451.txt.bz2 On Thursday 17 June 2010 00:57:52, Ian Lance Taylor wrote: > Doug Evans 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 Pedro Alves * 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