From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103910 invoked by alias); 22 May 2017 12:07:34 -0000 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 Received: (qmail 103896 invoked by uid 89); 22 May 2017 12:07:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LOTSOFHASH,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=H*RU:sk:static., Hx-spam-relays-external:sk:static., H*r:sk:clients, Hx-spam-relays-external:209.85.216.194 X-HELO: mail-qt0-f194.google.com Received: from mail-qt0-f194.google.com (HELO mail-qt0-f194.google.com) (209.85.216.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 22 May 2017 12:07:31 +0000 Received: by mail-qt0-f194.google.com with SMTP id r58so17786243qtb.2 for ; Mon, 22 May 2017 05:07:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=+wCEyR20682OW2h2L/RvKEQre5B9ZSRoXOTB7IHd2Jc=; b=l4X8p4syDxsxgSLDkxW8Zs6xwNrAeyp761D1s/DWG6vB7SvnFJ7E74zi2okWOruY85 CcH2T7SMVvTM+ARQ4FJDQi0eFS7Oh2yoibyE1kiTxvH3CvYXrVjbW6gXE3meF1J/JupS BeKNmYMMSqRLGssERoM91wMuCoM5vT1TyClSF+0m4kF4uHIiSoh+1QHY5+nfow9J3vQV NDUTlt6AnFhOMP8J4cCqox/wr0X84rsHcQlgMNx3Pzjpdhn2GG0pHKt6Gw11fvxzKd0n /Dtdzrwk8mcGQcA89bJk8MFI9N4o0x+bVayzoH1y/xVDIbG4RiyrhLUwhge7XwdgXQt6 kgdg== X-Gm-Message-State: AODbwcAzzyHyt3Y0GK1sqmWRhAlpA72S4qVDKTnM384oGJOrmcHdG8Ky lwwvCTLO/7QihV6G X-Received: by 10.237.62.200 with SMTP id o8mr20283122qtf.152.1495454853235; Mon, 22 May 2017 05:07:33 -0700 (PDT) Received: from E107787-LIN (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id z43sm11901435qtz.9.2017.05.22.05.07.31 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 22 May 2017 05:07:32 -0700 (PDT) From: Yao Qi To: Alan Hayward Cc: "gdb-patches\@sourceware.org" , nd Subject: Re: [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (2/4) References: <3C00280E-37C9-4C0A-9DA6-F3B9DB1A6E8F@arm.com> <86y3v7uf9j.fsf@gmail.com> <806B436F-EFA1-4200-AC54-9036D166C9B9@arm.com> <867f1m8nhm.fsf@gmail.com> Date: Mon, 22 May 2017 12:07:00 -0000 In-Reply-To: (Alan Hayward's message of "Tue, 16 May 2017 11:16:25 +0000") Message-ID: <8637bx9jsw.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-05/txt/msg00490.txt.bz2 Alan Hayward writes: > -extern ULONGEST extract_unsigned_integer (const gdb_byte *, int, > - enum bfd_endian); > +inline ULONGEST extract_unsigned_integer (const gdb_byte *addr, int len, > + enum bfd_endian byte_order) > +{ > + return extract_integer (addr, len, byte_order); s/LONGEST/ULONGEST/ > +} > [My C++ knowledge is still poor, so forgive me if I ask something stupid] Is there any reason you do not put function template (extract_integer and store_integer) in header? Any benefit of doing this? > extern int extract_long_unsigned_integer (const gdb_byte *, int, > enum bfd_endian, LONGEST *); > @@ -649,11 +664,21 @@ extern int extract_long_unsigned_integer (const gdb= _byte *, int, > extern CORE_ADDR extract_typed_address (const gdb_byte *buf, > struct type *type); > > -extern void store_signed_integer (gdb_byte *, int, > - enum bfd_endian, LONGEST); > +template void store_integer (gdb_byte *addr, int len, > + enum bfd_endian byte_order, > + LongType val); We can define store_integer slightly differently, so that we can use implicit instantiation, template typename std::enable_if<(std::is_same::value || std::is_same::value), void>::type store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order, T val) {} so that ... > > -extern void store_unsigned_integer (gdb_byte *, int, > - enum bfd_endian, ULONGEST); > +inline void store_signed_integer (gdb_byte *addr, int len, > + enum bfd_endian byte_order, LONGEST val) > +{ > + store_integer (addr, len, byte_order, val); ... the template argument can be deduced, store_integer (addr, len, byte_order, val); should be OK. > diff --git a/gdb/findvar.c b/gdb/findvar.c > index ed4d5c1266c9de069981b306bc8229ae5fb02350..3bcc98ce3421cb800fc822253= 5b16ca94ee043da 100644 > --- a/gdb/findvar.c > +++ b/gdb/findvar.c > @@ -46,70 +46,54 @@ > you lose > #endif > > -LONGEST > -extract_signed_integer (const gdb_byte *addr, int len, > - enum bfd_endian byte_order) > +template > +LongType > +extract_integer (const gdb_byte *addr, int len, enum bfd_endian byte_ord= er) > { > - LONGEST retval; > + T retval; > const unsigned char *p; > const unsigned char *startaddr =3D addr; > const unsigned char *endaddr =3D startaddr + len; > > - if (len > (int) sizeof (LONGEST)) > + if (len > (int) sizeof (T)) > error (_("\ > That operation is not available on integers of more than %d bytes."), > - (int) sizeof (LONGEST)); > + (int) sizeof (T)); > > /* Start at the most significant end of the integer, and work towards > the least significant. */ > if (byte_order =3D=3D BFD_ENDIAN_BIG) > { > p =3D startaddr; > - /* Do the sign extension once at the start. */ > - retval =3D ((LONGEST) * p ^ 0x80) - 0x80; > - for (++p; p < endaddr; ++p) > + if (std::is_signed::value) > + { > + /* Do the sign extension once at the start. */ > + retval =3D ((LONGEST) * p ^ 0x80) - 0x80; > + ++p; > + } Need to set retval to zero if (!std::is_signed::value), otherwise, retval might be not initialized. > diff --git a/gdb/mips-fbsd-tdep.c b/gdb/mips-fbsd-tdep.c > index 00fae0ec60ddc9e645d3236efe29f2f9e9ceab5c..1e391bfd16864d9d45f3b6e0d= e425aa5543515df 100644 > --- a/gdb/mips-fbsd-tdep.c > +++ b/gdb/mips-fbsd-tdep.c > @@ -48,9 +48,9 @@ > #define MIPS_FBSD_NUM_FPREGS 34 > > /* Supply a single register. If the source register size matches the > - size the regcache expects, this can use regcache_raw_supply(). If > + size the regcache expects, this can use regcache->raw_supply (). If > they are different, this copies the source register into a buffer > - that can be passed to regcache_raw_supply(). */ > + that can be passed to regcache->raw_supply (). */ > > static void > mips_fbsd_supply_reg (struct regcache *regcache, int regnum, const void = *addr, > @@ -63,20 +63,17 @@ mips_fbsd_supply_reg (struct regcache *regcache, int = regnum, const void *addr, > else > { > enum bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); > - gdb_byte buf[MAX_REGISTER_SIZE]; > LONGEST val; > > - val =3D extract_signed_integer ((const gdb_byte *) addr, len, byte= _order); > - store_signed_integer (buf, register_size (gdbarch, regnum), byte_o= rder, > - val); > - regcache_raw_supply (regcache, regnum, buf); > + val =3D extract_integer ((const gdb_byte *) addr, len, by= te_order); > + regcache->raw_supply (regnum, val); > } > } > > /* Collect a single register. If the destination register size > matches the size the regcache expects, this can use > - regcache_raw_supply(). If they are different, this fetches the > - register via regcache_raw_supply() into a buffer and then copies it > + regcache->raw_supply (). If they are different, this fetches the > + register via regcache->raw_supply () into a buffer and then copies it > into the final destination. */ > > static void > @@ -90,13 +87,8 @@ mips_fbsd_collect_reg (const struct regcache *regcache= , int regnum, void *addr, > else > { > enum bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); > - gdb_byte buf[MAX_REGISTER_SIZE]; > - LONGEST val; > - > - regcache_raw_collect (regcache, regnum, buf); > - val =3D extract_signed_integer (buf, register_size (gdbarch, regnu= m), > - byte_order); > - store_signed_integer ((gdb_byte *) addr, len, byte_order, val); > + LONGEST val =3D regcache->raw_collect (regnum); > + store_integer ((gdb_byte *) addr, len, byte_order, val); > } > } > > diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c > index 48a582a16c934abe6e8f87c46a6009649c606d49..bac106ed5e9e5d89285420beb= 52b33d6ce36265a 100644 > --- a/gdb/mips-linux-tdep.c > +++ b/gdb/mips-linux-tdep.c > @@ -118,11 +118,10 @@ supply_32bit_reg (struct regcache *regcache, int re= gnum, const void *addr) > { > struct gdbarch *gdbarch =3D get_regcache_arch (regcache); > enum bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); > - gdb_byte buf[MAX_REGISTER_SIZE]; > - store_signed_integer (buf, register_size (gdbarch, regnum), byte_order, > - extract_signed_integer ((const gdb_byte *) addr, 4, > - byte_order)); > - regcache_raw_supply (regcache, regnum, buf); > + LONGEST val; > + > + val =3D extract_integer ((const gdb_byte *) addr, 4, byte_ord= er); > + regcache->raw_supply (regnum, val); If we declare raw_supply a little bit differently (see below), we can do regcache->raw_supply (regnum, val); > } > > /* Unpack an elf_gregset_t into GDB's register cache. */ > @@ -460,14 +459,9 @@ mips64_fill_gregset (const struct regcache *regcache, > > if (regaddr !=3D -1) > { > - gdb_byte buf[MAX_REGISTER_SIZE]; > - LONGEST val; > - > - regcache_raw_collect (regcache, regno, buf); > - val =3D extract_signed_integer (buf, register_size (gdbarch, regno= ), > - byte_order); > + LONGEST val =3D regcache->raw_collect (regno); > dst =3D regp + regaddr; > - store_signed_integer ((gdb_byte *) dst, 8, byte_order, val); > + store_integer ((gdb_byte *) dst, 8, byte_order, val); Likewise, store_integer ((gdb_byte *) dst, 8, byte_order, val); > } > } > > diff --git a/gdb/regcache.h b/gdb/regcache.h > index 4dcfccbac70f0f962bf5e5596d035fda42322795..1ec8b98aa79c58c413786351a= 715ee46a0f5d5c2 100644 > --- a/gdb/regcache.h > +++ b/gdb/regcache.h > @@ -21,6 +21,7 @@ > #define REGCACHE_H > > #include "common-regcache.h" > +#include "defs.h" > > struct regcache; > struct regset; > @@ -294,8 +295,12 @@ public: > > void raw_collect (int regnum, void *buf) const; > > + template LongType raw_collect (int regnum) const; > + > void raw_supply (int regnum, const void *buf); > > + template void raw_supply (int regnum, LongType val); > + Similarly, we can do template typename std::enable_if<(std::is_same::value || std::is_same::value), void>::type raw_supply (int regnum, T val); so that we don't need to explicit instantiate it. > void raw_supply_zeroed (int regnum); > > void raw_copy (int regnum, struct regcache *src_regcache); > diff --git a/gdb/regcache.c b/gdb/regcache.c > index 957b265c28d929376c3b7d8c100ea355d8292b94..4facc6b55e2bd08972cce1081= b27e669103b6717 100644 > --- a/gdb/regcache.c > +++ b/gdb/regcache.c > @@ -1208,6 +1208,31 @@ regcache::raw_supply (int regnum, const void *buf) > } > } > > +/* Supply register REGNUM, whose contents are stored in VAL, to > + REGCACHE. */ > + > +template > +void > +regcache::raw_supply (int regnum, LongType val) > +{ > + enum bfd_endian byte_order =3D gdbarch_byte_order (m_descr->gdbarch); > + gdb_byte *regbuf; > + size_t size; > + > + gdb_assert (regnum >=3D 0 && regnum < m_descr->nr_raw_registers); > + gdb_assert (!m_readonly_p); > + > + regbuf =3D register_buffer (regnum); > + size =3D m_descr->sizeof_register[regnum]; > + > + store_integer (regbuf, size, byte_order, val); > + m_register_status[regnum] =3D REG_VALID; > +} Again, why don't you put it in regcache.h? --=20 Yao (=E9=BD=90=E5=B0=A7)