From 470c0b1c9a1d69e3c4f9281600399b1dadd40614 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Thu, 10 Oct 2019 10:48:01 +0100 Subject: gdb: Introduce global_symbol_searcher Introduce a new class to wrap up the parameters needed for the function search_symbols, which has now become a member function of this new class. The motivation is that search_symbols already takes a lot of parameters, and a future commit is going to add even more. This commit hopefully makes collecting the state required for a search easier. As part of this conversion the list of filenames in which to search has been converted to a std::vector. There should be no user visible changes after this commit. gdb/ChangeLog: * python/python.c (gdbpy_rbreak): Convert to using global_symbol_searcher. * symtab.c (file_matches): Convert return type to bool, change file list to std::vector, update header comment. (search_symbols): Rename to... (global_symbol_searcher::search): ...this and update now its a member function of global_symbol_searcher. Take account of the changes to file_matches. (symtab_symbol_info): Convert to using global_symbol_searcher. (rbreak_command): Likewise. (search_module_symbols): Likewise. * symtab.h (enum symbol_search): Update comment. (search_symbols): Remove declaration. (class global_symbol_searcher): New class. Change-Id: I488ab292a892d9e9e84775c632c5f198b6ad3710 --- gdb/python/python.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'gdb/python/python.c') diff --git a/gdb/python/python.c b/gdb/python/python.c index 2f4fb0f..fad54e9 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -644,19 +644,6 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) static PyObject * gdbpy_rbreak (PyObject *self, PyObject *args, PyObject *kw) { - /* A simple type to ensure clean up of a vector of allocated strings - when a C interface demands a const char *array[] type - interface. */ - struct symtab_list_type - { - ~symtab_list_type () - { - for (const char *elem: vec) - xfree ((void *) elem); - } - std::vector vec; - }; - char *regex = NULL; std::vector symbols; unsigned long count = 0; @@ -666,7 +653,6 @@ gdbpy_rbreak (PyObject *self, PyObject *args, PyObject *kw) unsigned int throttle = 0; static const char *keywords[] = {"regex","minsyms", "throttle", "symtabs", NULL}; - symtab_list_type symtab_paths; if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!IO", keywords, ®ex, &PyBool_Type, @@ -683,6 +669,12 @@ gdbpy_rbreak (PyObject *self, PyObject *args, PyObject *kw) minsyms_p = cmp; } + global_symbol_searcher spec (FUNCTIONS_DOMAIN, regex); + SCOPE_EXIT { + for (const char *elem : spec.filenames) + xfree ((void *) elem); + }; + /* The "symtabs" keyword is any Python iterable object that returns a gdb.Symtab on each iteration. If specified, iterate through the provided gdb.Symtabs and extract their full path. As @@ -728,20 +720,13 @@ gdbpy_rbreak (PyObject *self, PyObject *args, PyObject *kw) /* Make sure there is a definite place to store the value of filename before it is released. */ - symtab_paths.vec.push_back (nullptr); - symtab_paths.vec.back () = filename.release (); + spec.filenames.push_back (nullptr); + spec.filenames.back () = filename.release (); } } - if (symtab_list) - { - const char **files = symtab_paths.vec.data (); - - symbols = search_symbols (regex, FUNCTIONS_DOMAIN, NULL, - symtab_paths.vec.size (), files, false); - } - else - symbols = search_symbols (regex, FUNCTIONS_DOMAIN, NULL, 0, NULL, false); + /* The search spec. */ + symbols = spec.search (); /* Count the number of symbols (both symbols and optionally minimal symbols) so we can correctly check the throttle limit. */ -- cgit v1.1