public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [RFA 01/10] Remove some cleanups from search_minsyms_for_name
Date: Mon, 02 Apr 2018 01:39:00 -0000	[thread overview]
Message-ID: <8f38f8d0-fe2e-7023-dd57-7a32af834e4a@simark.ca> (raw)
In-Reply-To: <20180401163539.15314-2-tom@tromey.com>

On 2018-04-01 12:35 PM, Tom Tromey wrote:
> This changes struct collect_minsyms to use a std::vector, which
> enables the removal of a cleanup from search_minsyms_for_name.  This
> also changes iterate_over_minimal_symbols to take a
> gdb::function_view, which makes a function in linespec.c more
> type-safe.
> 
> gdb/ChangeLog
> 2018-03-31  Tom Tromey  <tom@tromey.com>
> 
> 	* minsyms.h (iterate_over_minimal_symbols): Update.
> 	* minsyms.c (iterate_over_minimal_symbols): Take a
> 	gdb::function_view.
> 	* linespec.c (struct collect_minsyms): Add constructor and
> 	initializers.
> 	<msyms>: Now a std::vector.
> 	(compare_msyms): Now a std::sort comparator.
> 	(add_minsym): Change type of second parameter.
> 	(search_minsyms_for_name): Update.
> ---
>  gdb/ChangeLog  |  12 +++++++
>  gdb/linespec.c | 112 ++++++++++++++++++++++++++++-----------------------------
>  gdb/minsyms.c  |   9 ++---
>  gdb/minsyms.h  |   8 ++---
>  4 files changed, 72 insertions(+), 69 deletions(-)
> 
> diff --git a/gdb/linespec.c b/gdb/linespec.c
> index 1236b3f475..bd09f57b05 100644
> --- a/gdb/linespec.c
> +++ b/gdb/linespec.c
> @@ -46,6 +46,7 @@
>  #include "location.h"
>  #include "common/function-view.h"
>  #include "common/def-vector.h"
> +#include <algorithm>
>  
>  /* An enumeration of the various things a user might attempt to
>     complete for a linespec location.  */
> @@ -4375,8 +4376,15 @@ minsym_found (struct linespec_state *self, struct objfile *objfile,
>  
>  struct collect_minsyms
>  {
> +  collect_minsyms (int funfirstline_, int list_mode_, struct symtab *symtab_)
> +    : symtab (symtab_),
> +      funfirstline (funfirstline_),

Note, funfirstline is unused, so you might as well remove it.

> +      list_mode (list_mode_)
> +  {
> +  }
> +
>    /* The objfile we're examining.  */
> -  struct objfile *objfile;
> +  struct objfile *objfile = nullptr;
>  
>    /* Only search the given symtab, or NULL to search for all symbols.  */
>    struct symtab *symtab;
> @@ -4388,7 +4396,7 @@ struct collect_minsyms
>    int list_mode;
>  
>    /* The resulting symbols.  */
> -  VEC (bound_minimal_symbol_d) *msyms;
> +  std::vector<struct bound_minimal_symbol> msyms;
>  };

I would lean towards removing the collect_minsyms structure and just pass anything
that's required by parameter to add_minsym.  It's easier to follow the flow of
execution when parameters are passed explicitly than through a structure.

>  
>  /* A helper function to classify a minimal_symbol_type according to
> @@ -4415,47 +4423,43 @@ classify_mtype (enum minimal_symbol_type t)
>      }
>  }
>  
> -/* Callback for qsort that sorts symbols by priority.  */
> +/* Callback for std::sort that sorts symbols by priority.  */
>  
> -static int
> -compare_msyms (const void *a, const void *b)
> +static bool
> +compare_msyms (const bound_minimal_symbol &a, const bound_minimal_symbol &b)
>  {
> -  const bound_minimal_symbol_d *moa = (const bound_minimal_symbol_d *) a;
> -  const bound_minimal_symbol_d *mob = (const bound_minimal_symbol_d *) b;
> -  enum minimal_symbol_type ta = MSYMBOL_TYPE (moa->minsym);
> -  enum minimal_symbol_type tb = MSYMBOL_TYPE (mob->minsym);
> +  enum minimal_symbol_type ta = MSYMBOL_TYPE (a.minsym);
> +  enum minimal_symbol_type tb = MSYMBOL_TYPE (b.minsym);
>  
> -  return classify_mtype (ta) - classify_mtype (tb);
> +  return classify_mtype (ta) < classify_mtype (tb);
>  }
>  
>  /* Callback for iterate_over_minimal_symbols that adds the symbol to
>     the result.  */

This comment should probably updated.  It is not really a callback for
iterate_over_minimal_symbols anymore (at least not directly).

>  
>  static void
> -add_minsym (struct minimal_symbol *minsym, void *d)
> +add_minsym (struct minimal_symbol *minsym, struct collect_minsyms &info)

...

> diff --git a/gdb/minsyms.c b/gdb/minsyms.c
> index 72969b7778..08efa1dc7e 100644
> --- a/gdb/minsyms.c
> +++ b/gdb/minsyms.c
> @@ -471,11 +471,8 @@ linkage_name_str (const lookup_name_info &lookup_name)
>  void
>  iterate_over_minimal_symbols (struct objfile *objf,
>  			      const lookup_name_info &lookup_name,
> -			      void (*callback) (struct minimal_symbol *,
> -						void *),
> -			      void *user_data)
> +			      gdb::function_view<void (struct minimal_symbol *)> callback)

This line is too long, you should probably wrap the whole parameter list.

>  {
> -
>    /* The first pass is over the ordinary hash table.  */
>      {
>        const char *name = linkage_name_str (lookup_name);
> @@ -490,7 +487,7 @@ iterate_over_minimal_symbols (struct objfile *objf,
>  	   iter = iter->hash_next)
>  	{
>  	  if (mangled_cmp (MSYMBOL_LINKAGE_NAME (iter), name) == 0)
> -	    (*callback) (iter, user_data);
> +	    callback (iter);
>  	}
>      }
>  
> @@ -509,7 +506,7 @@ iterate_over_minimal_symbols (struct objfile *objf,
>  	   iter != NULL;
>  	   iter = iter->demangled_hash_next)
>  	if (name_match (MSYMBOL_SEARCH_NAME (iter), lookup_name, NULL))
> -	  (*callback) (iter, user_data);
> +	  callback (iter);
>      }
>  }
>  
> diff --git a/gdb/minsyms.h b/gdb/minsyms.h
> index 11a202025d..b05f717575 100644
> --- a/gdb/minsyms.h
> +++ b/gdb/minsyms.h
> @@ -268,11 +268,9 @@ struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR);
>     For each matching symbol, CALLBACK is called with the symbol and
>     USER_DATA as arguments.  */

This comment should be updated.

>  
> -void iterate_over_minimal_symbols (struct objfile *objf,
> -				   const lookup_name_info &name,
> -				   void (*callback) (struct minimal_symbol *,
> -						     void *),
> -				   void *user_data);
> +void iterate_over_minimal_symbols
> +    (struct objfile *objf, const lookup_name_info &name,
> +     gdb::function_view<void (struct minimal_symbol *)> callback);
>  
>  /* Compute the upper bound of MINSYM.  The upper bound is the last
>     address thought to be part of the symbol.  If the symbol has a
> 

Thanks,

Simon

  reply	other threads:[~2018-04-02  1:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-01 16:35 [RFA 00/10] Remove some cleanups from linespec.c Tom Tromey
2018-04-01 16:35 ` [RFA 02/10] Fix some indentation in linespec.c Tom Tromey
2018-04-02  1:49   ` Simon Marchi
2018-04-01 16:35 ` [RFA 06/10] Remove a string copy from event_location_to_sals Tom Tromey
2018-04-01 16:35 ` [RFA 09/10] Remove typep and VEC(typep) from linespec.c Tom Tromey
2018-04-01 16:35 ` [RFA 01/10] Remove some cleanups from search_minsyms_for_name Tom Tromey
2018-04-02  1:39   ` Simon Marchi [this message]
2018-04-01 16:35 ` [RFA 05/10] Have filter_results take a std::vector Tom Tromey
2018-04-01 16:35 ` [RFA 04/10] Return std::string from canonical_to_fullform Tom Tromey
2018-04-02  2:15   ` Simon Marchi
2018-04-01 16:35 ` [RFA 10/10] Remove unnecessary include from linespec.h Tom Tromey
2018-04-01 16:35 ` [RFA 08/10] More use of std::vector in linespec.c Tom Tromey
2018-04-02  2:35   ` Simon Marchi
2018-04-01 16:35 ` [RFA 03/10] Make copy_token_string return unique_xmalloc_ptr Tom Tromey
2018-04-01 16:35 ` [RFA 07/10] Change streq to return bool Tom Tromey
2018-04-02  2:28   ` Simon Marchi
2018-04-02  2:44 ` [RFA 00/10] Remove some cleanups from linespec.c Simon Marchi
2018-04-03 22:31   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8f38f8d0-fe2e-7023-dd57-7a32af834e4a@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).