From dbd67812d20c8e2246e5cd576c88a8e7c11abdd7 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Feb 21 2017 21:32:55 +0000 Subject: Add search_symbols_multiple. NOTE: All this symbol stuff should be checked against Pedro's cp-linespec branch, which might clean-up a LOT of this. [Actually, I think Pedro's work might simplify gcc_cplus_convert_symbol and eliminate regexp_search_symbols and related nastiness.] --- diff --git a/gdb/linespec.c b/gdb/linespec.c index c758a8b..d15d6f2 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -58,10 +58,6 @@ struct address_entry CORE_ADDR addr; }; -typedef struct bound_minimal_symbol bound_minimal_symbol_d; - -DEF_VEC_O (bound_minimal_symbol_d); - /* A linespec. Elements of this structure are filled in by a parser (either parse_linespec or some other function). The structure is then converted into SALs by convert_linespec_to_sals. */ @@ -163,11 +159,7 @@ struct collect_info VEC (symtab_ptr) *file_symtabs; /* The result being accumulated. */ - struct - { - VEC (block_symbol_d) *symbols; - VEC (bound_minimal_symbol_d) *minimal_symbols; - } result; + struct search_multiple_result result; }; /* Token types */ @@ -3182,6 +3174,67 @@ symtabs_from_filename (const char *filename, return result; } +/* See description in symtab.h. */ + +struct search_multiple_result +search_symbols_multiple (const char *name, + const struct language_defn *language, + domain_enum domain, + VEC (symtab_ptr) *search_symtabs, + struct program_space *search_pspace) +{ + struct collect_info info; + struct linespec_state state; + struct cleanup *back_to = make_cleanup (null_cleanup, NULL); + + memset (&state, 0, sizeof (state)); + state.language = language; + info.state = &state; + info.result.symbols = NULL; + info.result.minimal_symbols = NULL; + info.file_symtabs = search_symtabs; + if (info.file_symtabs == NULL) + { + VEC_safe_push (symtab_ptr, info.file_symtabs, NULL); + make_cleanup (VEC_cleanup (symtab_ptr), &info.file_symtabs); + } + + add_matching_symbols_to_info (name, domain, &info, search_pspace); + + if (VEC_empty (block_symbol_d, info.result.symbols)) + { + VEC_free (block_symbol_d, info.result.symbols); + info.result.symbols = NULL; + } + if (VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) + { + VEC_free (bound_minimal_symbol_d, info.result.minimal_symbols); + info.result.minimal_symbols = NULL; + } + + do_cleanups (back_to); + return info.result; +} + +/* See description in symtab.h. */ + +void +free_search_multiple_result (struct search_multiple_result *result) +{ + VEC_free (block_symbol_d, result->symbols); + VEC_free (bound_minimal_symbol_d, result->minimal_symbols); +} + +/* See the description in symtab.h. */ + +void +search_multiple_result_cleanup (void *resultp) +{ + struct search_multiple_result *r = (struct search_multiple_result *) resultp; + + free_search_multiple_result (r); +} + /* Look up a function symbol named NAME in symtabs FILE_SYMTABS. Matching debug symbols are returned in SYMBOLS. Matching minimal symbols are returned in MINSYMS. */ diff --git a/gdb/minsyms.h b/gdb/minsyms.h index b82a22a..8d582b1 100644 --- a/gdb/minsyms.h +++ b/gdb/minsyms.h @@ -37,6 +37,9 @@ struct bound_minimal_symbol struct objfile *objfile; }; +typedef struct bound_minimal_symbol bound_minimal_symbol_d; +DEF_VEC_O (bound_minimal_symbol_d); + /* This header declares most of the API for dealing with minimal symbols and minimal symbol tables. A few things are declared elsewhere; see below. diff --git a/gdb/symtab.h b/gdb/symtab.h index df4ef85..07de87e 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1687,4 +1687,34 @@ void initialize_objfile_symbol (struct symbol *); struct template_symbol *allocate_template_symbol (struct objfile *); +/* Result of a multi-symbol search. */ + +struct search_multiple_result +{ + /* Matching debug symbols. */ + VEC (block_symbol_d) *symbols; + + /* Matching non-debug symbols. */ + VEC (bound_minimal_symbol_d) *minimal_symbols; +}; + +/* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting + search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL + to search all symtabs and program spaces. */ + +extern struct search_multiple_result + search_symbols_multiple (const char *name, + const struct language_defn *language, + domain_enum domain, + VEC (symtab_ptr) *file_symtabs, + struct program_space *search_pspace); + +/* Free the result of search_symbols_multiple. */ + +extern void free_search_multiple_result (struct search_multiple_result *); + +/* A cleanup function for the return result of search_symbols_multiple. */ + +extern void search_multiple_result_cleanup (void *); + #endif /* !defined(SYMTAB_H) */