From patchwork Sun Jun 10 21:51:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 27729 Received: (qmail 129424 invoked by alias); 10 Jun 2018 21:51:48 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 129407 invoked by uid 89); 10 Jun 2018 21:51:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=1259, forces, H*RU:sk:barracu, HX-HELO:sk:barracu X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Jun 2018 21:51:45 +0000 X-ASG-Debug-ID: 1528667488-0c856e7f582399f0001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id DJTrJ8DqidE0GraD (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 10 Jun 2018 17:51:28 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (unknown [192.222.164.54]) by smtp.ebox.ca (Postfix) with ESMTP id C4DDB441B21; Sun, 10 Jun 2018 17:51:28 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-164-54.qc.cable.ebox.net[192.222.164.54] X-Barracuda-Apparent-Source-IP: 192.222.164.54 X-Barracuda-RBL-IP: 192.222.164.54 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] Rename regcache_cooked_read_ftype and make a function_view Date: Sun, 10 Jun 2018 17:51:28 -0400 X-ASG-Orig-Subj: [PATCH] Rename regcache_cooked_read_ftype and make a function_view Message-Id: <20180610215128.20236-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1528667488 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 7128 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.51850 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes regcache_cooked_read_ftype can be converted to a function_view, which allows us to use lambda functions and therefore avoid having to pass an opaque pointer parameter. Adjusting the fallouts showed that the "const regcache &" passed to the readonly_detached_regcache constructor is cast to non-const in do_cooked_read. I changed the constructor parameter to be non-const. Finally, I renamed the typedef from regcache_cooked_read_ftype to register_read_ftype, since there is nothing that forces us to use it only for regcaches nor cooked registers. gdb/ChangeLog: * regcache.h (regcache_cooked_read_ftype): Rename to... (register_read_ftype): ...this, change type to function_view. (class reg_buffer) : Remove src parameter. (readonly_detached_regcache) : Make parameter non-const in first overload. Remove src parameter in second overload. * regcache.c (do_cooked_read): Remove. (readonly_detached_regcache::readonly_detached_regcache): Make parameter non-const, adjust call to other constructor. (reg_buffer::save): Remove src parameter. * frame.c (do_frame_register_read): Remove. (frame_save_as_regcache): Use lambda function. * ppc-linux-tdep.c (ppu2spu_unwind_register): Change type of src parameter to ppu2spu_data *. (ppu2spu_sniffer): Use lambda function. --- gdb/frame.c | 20 +++++++++----------- gdb/ppc-linux-tdep.c | 11 ++++++----- gdb/regcache.c | 21 ++++++++------------- gdb/regcache.h | 15 ++++++--------- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/gdb/frame.c b/gdb/frame.c index d8309e740706..450bf3a105ea 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1024,21 +1024,19 @@ get_frame_func (struct frame_info *this_frame) return pc; } -static enum register_status -do_frame_register_read (void *src, int regnum, gdb_byte *buf) -{ - if (!deprecated_frame_register_read ((struct frame_info *) src, regnum, buf)) - return REG_UNAVAILABLE; - else - return REG_VALID; -} - std::unique_ptr frame_save_as_regcache (struct frame_info *this_frame) { + auto cooked_read = [this_frame] (int regnum, gdb_byte *buf) + { + if (!deprecated_frame_register_read (this_frame, regnum, buf)) + return REG_UNAVAILABLE; + else + return REG_VALID; + }; + std::unique_ptr regcache - (new readonly_detached_regcache (get_frame_arch (this_frame), - do_frame_register_read, this_frame)); + (new readonly_detached_regcache (get_frame_arch (this_frame), cooked_read)); return regcache; } diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index f26882fe3c83..9f4c1fc891b7 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -1371,9 +1371,8 @@ struct ppu2spu_data }; static enum register_status -ppu2spu_unwind_register (void *src, int regnum, gdb_byte *buf) +ppu2spu_unwind_register (ppu2spu_data *data, int regnum, gdb_byte *buf) { - struct ppu2spu_data *data = (struct ppu2spu_data *) src; enum bfd_endian byte_order = gdbarch_byte_order (data->gdbarch); if (regnum >= 0 && regnum < SPU_NUM_GPRS) @@ -1435,12 +1434,14 @@ ppu2spu_sniffer (const struct frame_unwind *self, data.gprs, 0, sizeof data.gprs) == sizeof data.gprs) { + auto cooked_read = [&data] (int regnum, gdb_byte *buf) + { + return ppu2spu_unwind_register (&data, regnum, buf); + }; struct ppu2spu_cache *cache = FRAME_OBSTACK_CALLOC (1, struct ppu2spu_cache); std::unique_ptr regcache - (new readonly_detached_regcache (data.gdbarch, - ppu2spu_unwind_register, - &data)); + (new readonly_detached_regcache (data.gdbarch, cooked_read)); cache->frame_id = frame_id_build (base, func); cache->regcache = regcache.release (); diff --git a/gdb/regcache.c b/gdb/regcache.c index 3eed7b6304b5..3db7b9791f67 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -205,16 +205,12 @@ regcache::regcache (gdbarch *gdbarch, const address_space *aspace_) m_ptid = minus_one_ptid; } -static enum register_status -do_cooked_read (void *src, int regnum, gdb_byte *buf) -{ - struct regcache *regcache = (struct regcache *) src; - - return regcache->cooked_read (regnum, buf); -} - -readonly_detached_regcache::readonly_detached_regcache (const regcache &src) - : readonly_detached_regcache (src.arch (), do_cooked_read, (void *) &src) +readonly_detached_regcache::readonly_detached_regcache (regcache &src) + : readonly_detached_regcache (src.arch (), + [&src] (int regnum, gdb_byte *buf) + { + return src.cooked_read (regnum, buf); + }) { } @@ -264,8 +260,7 @@ reg_buffer::register_buffer (int regnum) const } void -reg_buffer::save (regcache_cooked_read_ftype *cooked_read, - void *src) +reg_buffer::save (register_read_ftype cooked_read) { struct gdbarch *gdbarch = m_descr->gdbarch; int regnum; @@ -284,7 +279,7 @@ reg_buffer::save (regcache_cooked_read_ftype *cooked_read, if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup)) { gdb_byte *dst_buf = register_buffer (regnum); - enum register_status status = cooked_read (src, regnum, dst_buf); + enum register_status status = cooked_read (regnum, dst_buf); gdb_assert (status != REG_UNKNOWN); diff --git a/gdb/regcache.h b/gdb/regcache.h index 2f460a02fac6..a11e32c410f6 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -125,9 +125,8 @@ extern struct type *register_type (struct gdbarch *gdbarch, int regnum); extern int register_size (struct gdbarch *gdbarch, int regnum); -typedef enum register_status (regcache_cooked_read_ftype) (void *src, - int regnum, - gdb_byte *buf); +typedef gdb::function_view + register_read_ftype; /* A (register_number, register_value) pair. */ @@ -166,7 +165,7 @@ protected: /* Save a register cache. The set of registers saved into the regcache determined by the save_reggroup. COOKED_READ returns zero iff the register's value can't be returned. */ - void save (regcache_cooked_read_ftype *cooked_read, void *src); + void save (register_read_ftype cooked_read); struct regcache_descr *m_descr; @@ -364,16 +363,14 @@ private: class readonly_detached_regcache : public readable_regcache { public: - readonly_detached_regcache (const regcache &src); + readonly_detached_regcache (regcache &src); /* Create a readonly regcache by getting contents from COOKED_READ. */ - readonly_detached_regcache (gdbarch *gdbarch, - regcache_cooked_read_ftype *cooked_read, - void *src) + readonly_detached_regcache (gdbarch *gdbarch, register_read_ftype cooked_read) : readable_regcache (gdbarch, true) { - save (cooked_read, src); + save (cooked_read); } DISABLE_COPY_AND_ASSIGN (readonly_detached_regcache);