From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id CCA0D3858D3C; Thu, 5 May 2022 19:27:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCA0D3858D3C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: use gdb::function_view for gdbarch_iterate_over_objfiles_in_search_order callback X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 1653ae5b8440e2182ac86974b99b603bc15aa163 X-Git-Newrev: 6e9cd73eb553c372153d6e9ba4934119623fdad3 Message-Id: <20220505192739.CCA0D3858D3C@sourceware.org> Date: Thu, 5 May 2022 19:27:39 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2022 19:27:39 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6e9cd73eb553= c372153d6e9ba4934119623fdad3 commit 6e9cd73eb553c372153d6e9ba4934119623fdad3 Author: Simon Marchi Date: Wed May 4 08:14:22 2022 -0400 gdb: use gdb::function_view for gdbarch_iterate_over_objfiles_in_search= _order callback =20 A rather straightforward patch to change an instance of callback + void pointer to gdb::function_view, allowing pasing lambdas that capture, and eliminating the need for the untyped pointer. =20 Change-Id: I73ed644e7849945265a2c763f79f5456695b0037 Diff: --- gdb/findvar.c | 55 +++++++++++------------------------------- gdb/gdbarch-components.py | 12 +++------- gdb/gdbarch-gen.h | 13 ++++------ gdb/gdbarch.c | 4 ++-- gdb/gdbarch.h | 4 ++-- gdb/objfiles.c | 14 ++++------- gdb/objfiles.h | 5 ++-- gdb/solib-svr4.c | 15 ++++++------ gdb/symtab.c | 61 +++++++------------------------------------= ---- gdb/windows-tdep.c | 23 +++++++----------- 10 files changed, 55 insertions(+), 151 deletions(-) diff --git a/gdb/findvar.c b/gdb/findvar.c index 1f0317567cd..36c094534be 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -399,37 +399,6 @@ symbol_read_needs_frame (struct symbol *sym) return symbol_read_needs (sym) =3D=3D SYMBOL_NEEDS_FRAME; } =20 -/* Private data to be used with minsym_lookup_iterator_cb. */ - -struct minsym_lookup_data -{ - /* The name of the minimal symbol we are searching for. */ - const char *name =3D nullptr; - - /* The field where the callback should store the minimal symbol - if found. It should be initialized to NULL before the search - is started. */ - struct bound_minimal_symbol result; -}; - -/* A callback function for gdbarch_iterate_over_objfiles_in_search_order. - It searches by name for a minimal symbol within the given OBJFILE. - The arguments are passed via CB_DATA, which in reality is a pointer - to struct minsym_lookup_data. */ - -static int -minsym_lookup_iterator_cb (struct objfile *objfile, void *cb_data) -{ - struct minsym_lookup_data *data =3D (struct minsym_lookup_data *) cb_dat= a; - - gdb_assert (data->result.minsym =3D=3D NULL); - - data->result =3D lookup_minimal_symbol (data->name, NULL, objfile); - - /* The iterator should stop iff a match was found. */ - return (data->result.minsym !=3D NULL); -} - /* Given static link expression and the frame it lives in, look for the fr= ame the static links points to and return it. Return NULL if we could not = find such a frame. */ @@ -746,22 +715,25 @@ language_defn::read_var_value (struct symbol *var, =20 case LOC_UNRESOLVED: { - struct minsym_lookup_data lookup_data; - struct minimal_symbol *msym; struct obj_section *obj_section; - - lookup_data.name =3D var->linkage_name (); + bound_minimal_symbol bmsym; =20 gdbarch_iterate_over_objfiles_in_search_order (var->arch (), - minsym_lookup_iterator_cb, &lookup_data, + [var, &bmsym] (objfile *objfile) + { + bmsym =3D lookup_minimal_symbol (var->linkage_name (), nullptr, + objfile); + + /* Stop if a match is found. */ + return bmsym.minsym !=3D nullptr; + }, var->objfile ()); - msym =3D lookup_data.result.minsym; =20 /* If we can't find the minsym there's a problem in the symbol info. The symbol exists in the debug info, but it's missing in the minsym table. */ - if (msym =3D=3D NULL) + if (bmsym.minsym =3D=3D nullptr) { const char *flavour_name =3D objfile_flavour_name (var->objfile ()); @@ -772,14 +744,15 @@ language_defn::read_var_value (struct symbol *var, error (_("Missing %s symbol \"%s\"."), flavour_name, var->linkage_name ()); } - obj_section =3D msym->obj_section (lookup_data.result.objfile); + + obj_section =3D bmsym.minsym->obj_section (bmsym.objfile); /* Relocate address, unless there is no section or the variable is a TLS variable. */ if (obj_section =3D=3D NULL || (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) !=3D 0) - addr =3D msym->value_raw_address (); + addr =3D bmsym.minsym->value_raw_address (); else - addr =3D lookup_data.result.value_address (); + addr =3D bmsym.value_address (); if (overlay_debugging) addr =3D symbol_overlayed_address (addr, obj_section); /* Determine address of TLS variable. */ diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py index e8f20c83ff0..fc10e8600ba 100644 --- a/gdb/gdbarch-components.py +++ b/gdb/gdbarch-components.py @@ -2362,13 +2362,8 @@ Method( Iterate over all objfiles in the order that makes the most sense for the architecture to make global symbol searches. =20 -CB is a callback function where OBJFILE is the objfile to be searched, -and CB_DATA a pointer to user-defined data (the same data that is passed -when calling this gdbarch method). The iteration stops if this function -returns nonzero. - -CB_DATA is a pointer to some user-defined data to be passed to -the callback. +CB is a callback function passed an objfile to be searched. The iteration= stops +if this function returns nonzero. =20 If not NULL, CURRENT_OBJFILE corresponds to the objfile being inspected when the symbol search was requested. @@ -2376,8 +2371,7 @@ inspected when the symbol search was requested. type=3D"void", name=3D"iterate_over_objfiles_in_search_order", params=3D[ - ("iterate_over_objfiles_in_search_order_cb_ftype *", "cb"), - ("void *", "cb_data"), + ("iterate_over_objfiles_in_search_order_cb_ftype", "cb"), ("struct objfile *", "current_objfile"), ], predefault=3D"default_iterate_over_objfiles_in_search_order", diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index 882b9057b1a..ddcb4c55615 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -1461,19 +1461,14 @@ extern void set_gdbarch_core_info_proc (struct gdba= rch *gdbarch, gdbarch_core_in /* Iterate over all objfiles in the order that makes the most sense for the architecture to make global symbol searches. =20 - CB is a callback function where OBJFILE is the objfile to be searched, - and CB_DATA a pointer to user-defined data (the same data that is passed - when calling this gdbarch method). The iteration stops if this function - returns nonzero. - - CB_DATA is a pointer to some user-defined data to be passed to - the callback. + CB is a callback function passed an objfile to be searched. The iterat= ion stops + if this function returns nonzero. =20 If not NULL, CURRENT_OBJFILE corresponds to the objfile being inspected when the symbol search was requested. */ =20 -typedef void (gdbarch_iterate_over_objfiles_in_search_order_ftype) (struct= gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype *cb, void= *cb_data, struct objfile *current_objfile); -extern void gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch = *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype *cb, void *cb_data= , struct objfile *current_objfile); +typedef void (gdbarch_iterate_over_objfiles_in_search_order_ftype) (struct= gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, struc= t objfile *current_objfile); +extern void gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch = *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, struct objfile= *current_objfile); extern void set_gdbarch_iterate_over_objfiles_in_search_order (struct gdba= rch *gdbarch, gdbarch_iterate_over_objfiles_in_search_order_ftype *iterate_= over_objfiles_in_search_order); =20 /* Ravenscar arch-dependent ops. */ diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index a588bdef61a..68ef0480219 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -4928,13 +4928,13 @@ set_gdbarch_core_info_proc (struct gdbarch *gdbarch, } =20 void -gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, it= erate_over_objfiles_in_search_order_cb_ftype *cb, void *cb_data, struct obj= file *current_objfile) +gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, it= erate_over_objfiles_in_search_order_cb_ftype cb, struct objfile *current_ob= jfile) { gdb_assert (gdbarch !=3D NULL); gdb_assert (gdbarch->iterate_over_objfiles_in_search_order !=3D NULL); if (gdbarch_debug >=3D 2) gdb_printf (gdb_stdlog, "gdbarch_iterate_over_objfiles_in_search_order= called\n"); - gdbarch->iterate_over_objfiles_in_search_order (gdbarch, cb, cb_data, cu= rrent_objfile); + gdbarch->iterate_over_objfiles_in_search_order (gdbarch, cb, current_obj= file); } =20 void diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 6404dc1cb43..3a7b7f92ef7 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -78,8 +78,8 @@ extern struct gdbarch *target_gdbarch (void); /* Callback type for the 'iterate_over_objfiles_in_search_order' gdbarch method. */ =20 -typedef int (iterate_over_objfiles_in_search_order_cb_ftype) - (struct objfile *objfile, void *cb_data); +using iterate_over_objfiles_in_search_order_cb_ftype + =3D gdb::function_view; =20 /* Callback type for regset section iterators. The callback usually invokes the REGSET's supply or collect method, to which it must diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 3f18e98710b..80f68fda1c1 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -1315,18 +1315,12 @@ shared_objfile_contains_address_p (struct program_s= pace *pspace, =20 void default_iterate_over_objfiles_in_search_order - (struct gdbarch *gdbarch, - iterate_over_objfiles_in_search_order_cb_ftype *cb, - void *cb_data, struct objfile *current_objfile) + (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, + objfile *current_objfile) { - int stop =3D 0; - for (objfile *objfile : current_program_space->objfiles ()) - { - stop =3D cb (objfile, cb_data); - if (stop) - return; - } + if (cb (objfile)) + return; } =20 /* See objfiles.h. */ diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 8bd76705688..cb7a1357cfe 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -903,9 +903,8 @@ extern scoped_restore_tmpl inhibit_section_map_upd= ates (struct program_space *pspace); =20 extern void default_iterate_over_objfiles_in_search_order - (struct gdbarch *gdbarch, - iterate_over_objfiles_in_search_order_cb_ftype *cb, - void *cb_data, struct objfile *current_objfile); + (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, + objfile *current_objfile); =20 /* Reset the per-BFD storage area on OBJ. */ =20 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 2f3e79d200f..5c046d3fab5 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -51,9 +51,9 @@ static int svr4_have_link_map_offsets (void); static void svr4_relocate_main_executable (void); static void svr4_free_library_list (void *p_list); static void probes_table_remove_objfile_probes (struct objfile *objfile); -static void svr4_iterate_over_objfiles_in_search_order ( - struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype = *cb, - void *cb_data, struct objfile *objfile); +static void svr4_iterate_over_objfiles_in_search_order + (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, + objfile *current_objfile); =20 =20 /* On SVR4 systems, a list of symbols in the dynamic linker where @@ -3135,9 +3135,8 @@ struct target_so_ops svr4_so_ops; =20 static void svr4_iterate_over_objfiles_in_search_order - (struct gdbarch *gdbarch, - iterate_over_objfiles_in_search_order_cb_ftype *cb, - void *cb_data, struct objfile *current_objfile) + (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, + objfile *current_objfile) { bool checked_current_objfile =3D false; if (current_objfile !=3D nullptr) @@ -3156,7 +3155,7 @@ svr4_iterate_over_objfiles_in_search_order && gdb_bfd_scan_elf_dyntag (DT_SYMBOLIC, abfd, nullptr, nullptr) =3D=3D= 1) { checked_current_objfile =3D true; - if (cb (current_objfile, cb_data) !=3D 0) + if (cb (current_objfile)) return; } } @@ -3165,7 +3164,7 @@ svr4_iterate_over_objfiles_in_search_order { if (checked_current_objfile && objfile =3D=3D current_objfile) continue; - if (cb (objfile, cb_data) !=3D 0) + if (cb (objfile)) return; } } diff --git a/gdb/symtab.c b/gdb/symtab.c index 4b33d6c91af..8564986f66d 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2627,47 +2627,6 @@ find_quick_global_symbol_language (const char *name,= const domain_enum domain) return language_unknown; } =20 -/* Private data to be used with lookup_symbol_global_iterator_cb. */ - -struct global_or_static_sym_lookup_data -{ - /* The name of the symbol we are searching for. */ - const char *name; - - /* The domain to use for our search. */ - domain_enum domain; - - /* The block index in which to search. */ - enum block_enum block_index; - - /* The field where the callback should store the symbol if found. - It should be initialized to {NULL, NULL} before the search is started= . */ - struct block_symbol result; -}; - -/* A callback function for gdbarch_iterate_over_objfiles_in_search_order. - It searches by name for a symbol in the block given by BLOCK_INDEX of t= he - given OBJFILE. The arguments for the search are passed via CB_DATA, wh= ich - in reality is a pointer to struct global_or_static_sym_lookup_data. */ - -static int -lookup_symbol_global_or_static_iterator_cb (struct objfile *objfile, - void *cb_data) -{ - struct global_or_static_sym_lookup_data *data =3D - (struct global_or_static_sym_lookup_data *) cb_data; - - gdb_assert (data->result.symbol =3D=3D NULL - && data->result.block =3D=3D NULL); - - data->result =3D lookup_symbol_in_objfile (objfile, data->block_index, - data->name, data->domain); - - /* If we found a match, tell the iterator to stop. Otherwise, - keep going. */ - return (data->result.symbol !=3D NULL); -} - /* This function contains the common code of lookup_{global,static}_symbol. OBJFILE is only used if BLOCK_INDEX is GLOBAL_SCOPE, in which case it is the objfile to start the lookup in. */ @@ -2680,7 +2639,6 @@ lookup_global_or_static_symbol (const char *name, { struct symbol_cache *cache =3D get_symbol_cache (current_program_space); struct block_symbol result; - struct global_or_static_sym_lookup_data lookup_data; struct block_symbol_cache *bsc; struct symbol_cache_slot *slot; =20 @@ -2700,16 +2658,15 @@ lookup_global_or_static_symbol (const char *name, =20 /* Do a global search (of global blocks, heh). */ if (result.symbol =3D=3D NULL) - { - memset (&lookup_data, 0, sizeof (lookup_data)); - lookup_data.name =3D name; - lookup_data.block_index =3D block_index; - lookup_data.domain =3D domain; - gdbarch_iterate_over_objfiles_in_search_order - (objfile !=3D NULL ? objfile->arch () : target_gdbarch (), - lookup_symbol_global_or_static_iterator_cb, &lookup_data, objfile); - result =3D lookup_data.result; - } + gdbarch_iterate_over_objfiles_in_search_order + (objfile !=3D NULL ? objfile->arch () : target_gdbarch (), + [&result, block_index, name, domain] (struct objfile *objfile_iter) + { + result =3D lookup_symbol_in_objfile (objfile_iter, block_index, + name, domain); + return result.symbol !=3D nullptr; + }, + objfile); =20 if (result.symbol !=3D NULL) symbol_cache_mark_found (bsc, slot, objfile, result.symbol, result.blo= ck); diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c index 9049f1e17f5..2516e4ed058 100644 --- a/gdb/windows-tdep.c +++ b/gdb/windows-tdep.c @@ -573,28 +573,21 @@ windows_xfer_shared_library (const char* so_name, COR= E_ADDR load_addr, =20 static void windows_iterate_over_objfiles_in_search_order - (struct gdbarch *gdbarch, - iterate_over_objfiles_in_search_order_cb_ftype *cb, - void *cb_data, struct objfile *current_objfile) + (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, + objfile *current_objfile) { - int stop; - if (current_objfile) { - stop =3D cb (current_objfile, cb_data); - if (stop) + if (cb (current_objfile)) return; } =20 for (objfile *objfile : current_program_space->objfiles ()) - { - if (objfile !=3D current_objfile) - { - stop =3D cb (objfile, cb_data); - if (stop) - return; - } - } + if (objfile !=3D current_objfile) + { + if (cb (objfile)) + return; + } } =20 static void