From patchwork Sun Oct 8 17:07:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23392 Received: (qmail 42001 invoked by alias); 8 Oct 2017 17:07:58 -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 41799 invoked by uid 89); 8 Oct 2017 17:07:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=tromey, user's X-HELO: outbound-ss-1812.hostmonster.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO outbound-ss-1812.hostmonster.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Oct 2017 17:07:49 +0000 Received: from cmgw3 (cmgw4 [10.0.90.84]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id AA7E6175C3A for ; Sun, 8 Oct 2017 11:07:47 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id K57k1w00E2f2jeq0157nsn; Sun, 08 Oct 2017 11:07:47 -0600 X-Authority-Analysis: v=2.2 cv=K/VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=HJFErF2XIT1ZTg_R65sA:9 a=0wnFMhLi8jX9CDoZ:21 a=Sa2aClYGlvvs4qOl:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-4-236.hlrn.qwest.net ([75.166.4.236]:40508 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e1F3I-001zcc-AY; Sun, 08 Oct 2017 11:07:44 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/3] Use gdb::function_view in pv_area Date: Sun, 8 Oct 2017 11:07:41 -0600 Message-Id: <20171008170741.23151-4-tom@tromey.com> In-Reply-To: <20171008170741.23151-1-tom@tromey.com> References: <20171008170741.23151-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1e1F3I-001zcc-AY X-Source-Sender: 75-166-4-236.hlrn.qwest.net (bapiya.localdomain) [75.166.4.236]:40508 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes pv_area::scan to use gdb::function_view and updates all the callers. The primary gain from this change is type-safety in the calling code. gdb/ChangeLog 2017-10-07 Tom Tromey * rl78-tdep.c (rl78_analyze_prologue): Update. (check_for_saved): Change type of "result". * msp430-tdep.c (check_for_saved): Change type of "result". (msp430_analyze_prologue): Update. * rx-tdep.c (rx_analyze_prologue): Update. (check_for_saved): Change type of "result". * mn10300-tdep.c (mn10300_analyze_prologue): Update. (check_for_saved): Change type of "result". * m32c-tdep.c (m32c_analyze_prologue): Update. (check_for_saved): Change type of "prologue". * s390-linux-tdep.c (s390_check_for_saved): Change type of "data". (s390_analyze_prologue): Update. * mep-tdep.c (check_for_saved): Change type of "result". (mep_analyze_prologue): Update. * prologue-value.h (pv_area::scan): Use gdb::function_view. --- gdb/ChangeLog | 19 +++++++++++++++++++ gdb/m32c-tdep.c | 8 +++++--- gdb/mep-tdep.c | 9 +++++---- gdb/mn10300-tdep.c | 9 +++++---- gdb/msp430-tdep.c | 9 +++++---- gdb/prologue-value.c | 10 ++++------ gdb/prologue-value.h | 14 +++++++------- gdb/rl78-tdep.c | 8 ++++---- gdb/rx-tdep.c | 9 +++++---- gdb/s390-linux-tdep.c | 7 ++++--- 10 files changed, 63 insertions(+), 39 deletions(-) diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c index 39f9ec0e5a..62d575b3ef 100644 --- a/gdb/m32c-tdep.c +++ b/gdb/m32c-tdep.c @@ -36,6 +36,7 @@ #include "prologue-value.h" #include "target.h" #include "objfiles.h" +#include /* The m32c tdep structure. */ @@ -1499,9 +1500,9 @@ m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src) offset from the frame base, and SIZE indicates that the whole register was saved, record its offset in RESULT_UNTYPED. */ static void -check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value) +check_for_saved (struct m32c_prologue *prologue, pv_t addr, CORE_ADDR size, + pv_t value) { - struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped; struct gdbarch *arch = prologue->arch; struct gdbarch_tdep *tdep = gdbarch_tdep (arch); @@ -1811,7 +1812,8 @@ m32c_analyze_prologue (struct gdbarch *arch, prologue->kind = prologue_first_frame; /* Record where all the registers were saved. */ - st.stack->scan (check_for_saved, (void *) prologue); + using namespace std::placeholders; + stack.scan (std::bind (check_for_saved, prologue, _1, _2, _3)); prologue->prologue_end = after_last_frame_related_insn; } diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c index bf08ca14d2..1589764a5d 100644 --- a/gdb/mep-tdep.c +++ b/gdb/mep-tdep.c @@ -45,6 +45,7 @@ #include "prologue-value.h" #include "cgen/bitset.h" #include "infcall.h" +#include /* Get the user's customized MeP coprocessor register names from libopcodes. */ @@ -1651,10 +1652,9 @@ is_arg_spill (struct gdbarch *gdbarch, pv_t value, pv_t addr, offset from the frame base, and SIZE indicates that the whole register was saved, record its offset in RESULT_UNTYPED. */ static void -check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value) +check_for_saved (struct mep_prologue *result, pv_t addr, CORE_ADDR size, + pv_t value) { - struct mep_prologue *result = (struct mep_prologue *) result_untyped; - if (value.kind == pvk_register && value.k == 0 && pv_is_register (addr, MEP_SP_REGNUM) @@ -1884,7 +1884,8 @@ mep_analyze_prologue (struct gdbarch *gdbarch, } /* Record where all the registers were saved. */ - stack.scan (check_for_saved, (void *) result); + using namespace std::placeholders; + stack.scan (std::bind (check_for_saved, result, _1, _2, _3)); result->prologue_end = after_last_frame_setup_insn; } diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c index eadbbb367e..ebd35cf9d3 100644 --- a/gdb/mn10300-tdep.c +++ b/gdb/mn10300-tdep.c @@ -33,6 +33,7 @@ #include "infcall.h" #include "prologue-value.h" #include "target.h" +#include #include "mn10300-tdep.h" @@ -362,10 +363,9 @@ translate_rreg (int rreg) offset from the frame base, and SIZE indicates that the whole register was saved, record its offset in RESULT_UNTYPED. */ static void -check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value) +check_for_saved (struct mn10300_prologue *result, pv_t addr, CORE_ADDR size, + pv_t value) { - struct mn10300_prologue *result = (struct mn10300_prologue *) result_untyped; - if (value.kind == pvk_register && value.k == 0 && pv_is_register (addr, E_SP_REGNUM) @@ -1034,7 +1034,8 @@ mn10300_analyze_prologue (struct gdbarch *gdbarch, } /* Record where all the registers were saved. */ - stack.scan (check_for_saved, (void *) result); + using namespace std::placeholders; + stack.scan (std::bind (check_for_saved, result, _1, _2, _3)); result->prologue_end = after_last_frame_setup_insn; } diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c index 771ac9cd04..15ae2cff1e 100644 --- a/gdb/msp430-tdep.c +++ b/gdb/msp430-tdep.c @@ -34,6 +34,7 @@ #include "gdbcore.h" #include "dwarf2-frame.h" #include "reggroups.h" +#include #include "elf/msp430.h" #include "opcode/msp430-decode.h" @@ -318,10 +319,9 @@ msp430_get_opcode_byte (void *handle) register was saved, record its offset. */ static void -check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value) +check_for_saved (struct msp430_prologue *result, pv_t addr, CORE_ADDR size, + pv_t value) { - struct msp430_prologue *result = (struct msp430_prologue *) result_untyped; - if (value.kind == pvk_register && value.k == 0 && pv_is_register (addr, MSP430_SP_REGNUM) @@ -425,7 +425,8 @@ msp430_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc, result->frame_size = reg[MSP430_SP_REGNUM].k; /* Record where all the registers were saved. */ - stack.scan (check_for_saved, result); + using namespace std::placeholders; + stack.scan (std::bind (check_for_saved, result, _1, _2, _3)); result->prologue_end = after_last_frame_setup_insn; } diff --git a/gdb/prologue-value.c b/gdb/prologue-value.c index 2b2e5a8b65..b9b6667580 100644 --- a/gdb/prologue-value.c +++ b/gdb/prologue-value.c @@ -505,11 +505,9 @@ pv_area::find_reg (struct gdbarch *gdbarch, int reg, CORE_ADDR *offset_p) void -pv_area::scan (void (*func) (void *closure, - pv_t addr, - CORE_ADDR size, - pv_t value), - void *closure) +pv_area::scan (gdb::function_view func) { struct area_entry *e = m_entry; pv_t addr; @@ -521,7 +519,7 @@ pv_area::scan (void (*func) (void *closure, do { addr.k = e->offset; - func (closure, addr, e->size, e->value); + func (addr, e->size, e->value); e = e->next; } while (e != m_entry); diff --git a/gdb/prologue-value.h b/gdb/prologue-value.h index c6fd34bdab..b70521b877 100644 --- a/gdb/prologue-value.h +++ b/gdb/prologue-value.h @@ -19,6 +19,8 @@ #ifndef PROLOGUE_VALUE_H #define PROLOGUE_VALUE_H +#include "common/function-view.h" + /* What sort of value is this? This determines the interpretation of subsequent fields. */ enum prologue_value_kind @@ -283,13 +285,11 @@ public: bool find_reg (struct gdbarch *gdbarch, int reg, CORE_ADDR *offset_p); - /* For every part of AREA whose value we know, apply FUNC to CLOSURE, - the value's address, its size, and the value itself. */ - void scan (void (*func) (void *closure, - pv_t addr, - CORE_ADDR size, - pv_t value), - void *closure); + /* For every part of AREA whose value we know, apply FUNC to the + value's address, its size, and the value itself. */ + void scan (gdb::function_view); private: diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c index 19f8098b7b..b3a2f8d513 100644 --- a/gdb/rl78-tdep.c +++ b/gdb/rl78-tdep.c @@ -34,6 +34,7 @@ #include "gdbcore.h" #include "dwarf2-frame.h" #include "reggroups.h" +#include #include "elf/rl78.h" #include "elf-bfd.h" @@ -890,11 +891,9 @@ rl78_get_opcode_byte (void *handle) register was saved, record its offset. */ static void -check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, +check_for_saved (struct rl78_prologue *result, pv_t addr, CORE_ADDR size, pv_t value) { - struct rl78_prologue *result = (struct rl78_prologue *) result_untyped; - if (value.kind == pvk_register && value.k == 0 && pv_is_register (addr, RL78_SP_REGNUM) @@ -1013,7 +1012,8 @@ rl78_analyze_prologue (CORE_ADDR start_pc, result->frame_size = reg[RL78_SP_REGNUM].k; /* Record where all the registers were saved. */ - stack.scan (check_for_saved, (void *) result); + using namespace std::placeholders; + stack.scan (std::bind (check_for_saved, result, _1, _2, _3)); result->prologue_end = after_last_frame_setup_insn; } diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c index 7d0436c33f..7ef18f4b0a 100644 --- a/gdb/rx-tdep.c +++ b/gdb/rx-tdep.c @@ -37,6 +37,7 @@ #include "elf/rx.h" #include "elf-bfd.h" #include +#include /* Certain important register numbers. */ enum @@ -236,10 +237,9 @@ rx_register_type (struct gdbarch *gdbarch, int reg_nr) offset from the frame base, and SIZE indicates that the whole register was saved, record its offset. */ static void -check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value) +check_for_saved (struct rx_prologue *result, pv_t addr, CORE_ADDR size, + pv_t value) { - struct rx_prologue *result = (struct rx_prologue *) result_untyped; - if (value.kind == pvk_register && value.k == 0 && pv_is_register (addr, RX_SP_REGNUM) @@ -453,7 +453,8 @@ rx_analyze_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc, } /* Record where all the registers were saved. */ - stack.scan (check_for_saved, (void *) result); + using namespace std::placeholders; + stack.scan (std::bind (check_for_saved, result, _1, _2, _3)); result->prologue_end = after_last_frame_setup_insn; } diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c index d48364b93f..e56cbf3f0e 100644 --- a/gdb/s390-linux-tdep.c +++ b/gdb/s390-linux-tdep.c @@ -58,6 +58,7 @@ #include "elf/s390.h" #include "elf-bfd.h" #include +#include #include "features/s390-linux32.c" #include "features/s390-linux32v1.c" @@ -1424,10 +1425,9 @@ s390_load (struct s390_prologue_data *data, register was saved, record its offset in the reg_offset table in PROLOGUE_UNTYPED. */ static void -s390_check_for_saved (void *data_untyped, pv_t addr, +s390_check_for_saved (struct s390_prologue_data *data, pv_t addr, CORE_ADDR size, pv_t value) { - struct s390_prologue_data *data = (struct s390_prologue_data *) data_untyped; int i, offset; if (!pv_is_register (addr, S390_SP_REGNUM)) @@ -1731,7 +1731,8 @@ s390_analyze_prologue (struct gdbarch *gdbarch, } /* Record where all the registers were saved. */ - data->stack->scan (s390_check_for_saved, data); + using namespace std::placeholders; + data->stack->scan (std::bind (s390_check_for_saved, data, _1, _2, _3)); return result; }