This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 3/3] Use gdb::function_view in pv_area


On 2017-10-08 01:07 PM, Tom Tromey wrote:
> 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  <tom@tromey.com>
> 
> 	* 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 <functional>
>  
>  
>  /* 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));

For readability, I would be inclined to use lambdas for these.  For performance,
I have read that lambdas were preferable to std::bind, in that they were always
at least as efficient, often more.  But I don't know about that specific case,
since we go through a function_view.  If we put the scan method in the header,
then we could use a template parameter for the callback type instead of
gdb::function_vew.  I think that would be the most efficient, since it would
allow the compiler to optimize through the callback, as the whole call chain
would be known at compile-time.

It would be interesting if somebody with more C++-fu looked at it.

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]