Change decode_compound_collector to use std::vector
This patch changes decode_compound_collector to use std::vector instead of VEC, eliminating a cleanup in the process. gdb/ChangeLog: * linespec.c (decode_compound_collector::decode_compound_collector): Remove initialization for `m_symtabs'. (decode_compound_collector::release_symbols): Change return type to std::vector. Update all callers. (class decode_compound_collector) <m_symbols>: Change type to std::vector. (lookup_prefix_sym): Change return type to std::vector. Update all callers. (compare_symbols): Remove. (std_compare_symbols): Rename to `compare_symbols'. (find_method): Change `sym_classes' parameter to std::vector. Update all callers. Use std::sort to sort sym_classes. (find_linespec_symbols): Remove cleanup.
This commit is contained in:
parent
c2a031c582
commit
4dedf84da9
2 changed files with 37 additions and 64 deletions
|
@ -1,3 +1,19 @@
|
||||||
|
2018-08-29 Keith Seitz <keiths@redhat.com>
|
||||||
|
|
||||||
|
* linespec.c (decode_compound_collector::decode_compound_collector):
|
||||||
|
Remove initialization for `m_symtabs'.
|
||||||
|
(decode_compound_collector::release_symbols): Change return type
|
||||||
|
to std::vector. Update all callers.
|
||||||
|
(class decode_compound_collector) <m_symbols>: Change type to
|
||||||
|
std::vector.
|
||||||
|
(lookup_prefix_sym): Change return type to std::vector. Update all
|
||||||
|
callers.
|
||||||
|
(compare_symbols): Remove.
|
||||||
|
(std_compare_symbols): Rename to `compare_symbols'.
|
||||||
|
(find_method): Change `sym_classes' parameter to std::vector.
|
||||||
|
Update all callers. Use std::sort to sort sym_classes.
|
||||||
|
(find_linespec_symbols): Remove cleanup.
|
||||||
|
|
||||||
2018-08-29 Keith Seitz <keiths@redhat.com>
|
2018-08-29 Keith Seitz <keiths@redhat.com>
|
||||||
|
|
||||||
* linespec.c (struct linespec) <minimal_symbols>: Change type to
|
* linespec.c (struct linespec) <minimal_symbols>: Change type to
|
||||||
|
|
|
@ -400,9 +400,7 @@ static void minsym_found (struct linespec_state *self, struct objfile *objfile,
|
||||||
struct minimal_symbol *msymbol,
|
struct minimal_symbol *msymbol,
|
||||||
std::vector<symtab_and_line> *result);
|
std::vector<symtab_and_line> *result);
|
||||||
|
|
||||||
static int compare_symbols (const void *a, const void *b);
|
static bool compare_symbols (const struct symbol *a, const struct symbol *b);
|
||||||
static bool std_compare_symbols (const struct symbol *a,
|
|
||||||
const struct symbol *b);
|
|
||||||
|
|
||||||
static bool compare_msymbols (const bound_minimal_symbol &a,
|
static bool compare_msymbols (const bound_minimal_symbol &a,
|
||||||
const bound_minimal_symbol &b);
|
const bound_minimal_symbol &b);
|
||||||
|
@ -2266,7 +2264,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
|
||||||
to each other. */
|
to each other. */
|
||||||
std::sort (ls->function_symbols->begin (),
|
std::sort (ls->function_symbols->begin (),
|
||||||
ls->function_symbols->end (),
|
ls->function_symbols->end (),
|
||||||
std_compare_symbols);
|
compare_symbols);
|
||||||
|
|
||||||
for (const auto &sym : *ls->function_symbols)
|
for (const auto &sym : *ls->function_symbols)
|
||||||
{
|
{
|
||||||
|
@ -3501,7 +3499,6 @@ class decode_compound_collector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
decode_compound_collector ()
|
decode_compound_collector ()
|
||||||
: m_symbols (NULL)
|
|
||||||
{
|
{
|
||||||
m_unique_syms = htab_create_alloc (1, htab_hash_pointer,
|
m_unique_syms = htab_create_alloc (1, htab_hash_pointer,
|
||||||
htab_eq_pointer, NULL,
|
htab_eq_pointer, NULL,
|
||||||
|
@ -3514,12 +3511,10 @@ public:
|
||||||
htab_delete (m_unique_syms);
|
htab_delete (m_unique_syms);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Releases ownership of the collected symbols and returns them. */
|
/* Return all symbols collected. */
|
||||||
VEC (symbolp) *release_symbols ()
|
std::vector<symbol *> release_symbols ()
|
||||||
{
|
{
|
||||||
VEC (symbolp) *res = m_symbols;
|
return std::move (m_symbols);
|
||||||
m_symbols = NULL;
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callable as a symbol_found_callback_ftype callback. */
|
/* Callable as a symbol_found_callback_ftype callback. */
|
||||||
|
@ -3531,7 +3526,7 @@ private:
|
||||||
htab_t m_unique_syms;
|
htab_t m_unique_syms;
|
||||||
|
|
||||||
/* The result vector. */
|
/* The result vector. */
|
||||||
VEC (symbolp) *m_symbols;
|
std::vector<symbol *> m_symbols;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -3554,7 +3549,7 @@ decode_compound_collector::operator () (symbol *sym)
|
||||||
if (!*slot)
|
if (!*slot)
|
||||||
{
|
{
|
||||||
*slot = sym;
|
*slot = sym;
|
||||||
VEC_safe_push (symbolp, m_symbols, sym);
|
m_symbols.push_back (sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true; /* Continue iterating. */
|
return true; /* Continue iterating. */
|
||||||
|
@ -3564,7 +3559,7 @@ decode_compound_collector::operator () (symbol *sym)
|
||||||
|
|
||||||
/* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS. */
|
/* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS. */
|
||||||
|
|
||||||
static VEC (symbolp) *
|
static std::vector<symbol *>
|
||||||
lookup_prefix_sym (struct linespec_state *state,
|
lookup_prefix_sym (struct linespec_state *state,
|
||||||
std::vector<symtab *> *file_symtabs,
|
std::vector<symtab *> *file_symtabs,
|
||||||
const char *class_name)
|
const char *class_name)
|
||||||
|
@ -3603,7 +3598,7 @@ lookup_prefix_sym (struct linespec_state *state,
|
||||||
symbols with the same program space end up next to each other. */
|
symbols with the same program space end up next to each other. */
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
std_compare_symbols (const struct symbol *a, const struct symbol *b)
|
compare_symbols (const struct symbol *a, const struct symbol *b)
|
||||||
{
|
{
|
||||||
uintptr_t uia, uib;
|
uintptr_t uia, uib;
|
||||||
|
|
||||||
|
@ -3624,36 +3619,6 @@ std_compare_symbols (const struct symbol *a, const struct symbol *b)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A qsort comparison function for symbols. The resulting order does
|
|
||||||
not actually matter; we just need to be able to sort them so that
|
|
||||||
symbols with the same program space end up next to each other. */
|
|
||||||
|
|
||||||
static int
|
|
||||||
compare_symbols (const void *a, const void *b)
|
|
||||||
{
|
|
||||||
struct symbol * const *sa = (struct symbol * const*) a;
|
|
||||||
struct symbol * const *sb = (struct symbol * const*) b;
|
|
||||||
uintptr_t uia, uib;
|
|
||||||
|
|
||||||
uia = (uintptr_t) SYMTAB_PSPACE (symbol_symtab (*sa));
|
|
||||||
uib = (uintptr_t) SYMTAB_PSPACE (symbol_symtab (*sb));
|
|
||||||
|
|
||||||
if (uia < uib)
|
|
||||||
return -1;
|
|
||||||
if (uia > uib)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
uia = (uintptr_t) *sa;
|
|
||||||
uib = (uintptr_t) *sb;
|
|
||||||
|
|
||||||
if (uia < uib)
|
|
||||||
return -1;
|
|
||||||
if (uia > uib)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Like compare_symbols but for minimal symbols. */
|
/* Like compare_symbols but for minimal symbols. */
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -3723,11 +3688,9 @@ find_superclass_methods (std::vector<struct type *> &&superclasses,
|
||||||
static void
|
static void
|
||||||
find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
|
find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
|
||||||
const char *class_name, const char *method_name,
|
const char *class_name, const char *method_name,
|
||||||
VEC (symbolp) *sym_classes, std::vector<symbol *> *symbols,
|
std::vector<symbol *> *sym_classes, std::vector<symbol *> *symbols,
|
||||||
std::vector<bound_minimal_symbol> *minsyms)
|
std::vector<bound_minimal_symbol> *minsyms)
|
||||||
{
|
{
|
||||||
struct symbol *sym;
|
|
||||||
int ix;
|
|
||||||
size_t last_result_len;
|
size_t last_result_len;
|
||||||
std::vector<struct type *> superclass_vec;
|
std::vector<struct type *> superclass_vec;
|
||||||
std::vector<const char *> result_names;
|
std::vector<const char *> result_names;
|
||||||
|
@ -3735,9 +3698,7 @@ find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
|
||||||
|
|
||||||
/* Sort symbols so that symbols with the same program space are next
|
/* Sort symbols so that symbols with the same program space are next
|
||||||
to each other. */
|
to each other. */
|
||||||
qsort (VEC_address (symbolp, sym_classes),
|
std::sort (sym_classes->begin (), sym_classes->end (),
|
||||||
VEC_length (symbolp, sym_classes),
|
|
||||||
sizeof (symbolp),
|
|
||||||
compare_symbols);
|
compare_symbols);
|
||||||
|
|
||||||
info.state = self;
|
info.state = self;
|
||||||
|
@ -3755,7 +3716,8 @@ find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
|
||||||
because we collect data across the program space before deciding
|
because we collect data across the program space before deciding
|
||||||
what to do. */
|
what to do. */
|
||||||
last_result_len = 0;
|
last_result_len = 0;
|
||||||
for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix)
|
unsigned int ix = 0;
|
||||||
|
for (const auto &sym : *sym_classes)
|
||||||
{
|
{
|
||||||
struct type *t;
|
struct type *t;
|
||||||
struct program_space *pspace;
|
struct program_space *pspace;
|
||||||
|
@ -3771,10 +3733,9 @@ find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
|
||||||
|
|
||||||
/* Handle all items from a single program space at once; and be
|
/* Handle all items from a single program space at once; and be
|
||||||
sure not to miss the last batch. */
|
sure not to miss the last batch. */
|
||||||
if (ix == VEC_length (symbolp, sym_classes) - 1
|
if (ix == sym_classes->size () - 1
|
||||||
|| (pspace
|
|| (pspace
|
||||||
!= SYMTAB_PSPACE (symbol_symtab (VEC_index (symbolp, sym_classes,
|
!= SYMTAB_PSPACE (symbol_symtab (sym_classes->at (ix + 1)))))
|
||||||
ix + 1)))))
|
|
||||||
{
|
{
|
||||||
/* If we did not find a direct implementation anywhere in
|
/* If we did not find a direct implementation anywhere in
|
||||||
this program space, consider superclasses. */
|
this program space, consider superclasses. */
|
||||||
|
@ -3790,6 +3751,7 @@ find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
|
||||||
|
|
||||||
superclass_vec.clear ();
|
superclass_vec.clear ();
|
||||||
last_result_len = result_names.size ();
|
last_result_len = result_names.size ();
|
||||||
|
++ix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3976,7 +3938,6 @@ find_linespec_symbols (struct linespec_state *state,
|
||||||
{
|
{
|
||||||
std::string klass, method;
|
std::string klass, method;
|
||||||
const char *last, *p, *scope_op;
|
const char *last, *p, *scope_op;
|
||||||
VEC (symbolp) *classes;
|
|
||||||
|
|
||||||
/* See if we can find a scope operator and break this symbol
|
/* See if we can find a scope operator and break this symbol
|
||||||
name into namespaces${SCOPE_OPERATOR}class_name and method_name. */
|
name into namespaces${SCOPE_OPERATOR}class_name and method_name. */
|
||||||
|
@ -4005,18 +3966,16 @@ find_linespec_symbols (struct linespec_state *state,
|
||||||
method = last;
|
method = last;
|
||||||
|
|
||||||
/* Find a list of classes named KLASS. */
|
/* Find a list of classes named KLASS. */
|
||||||
classes = lookup_prefix_sym (state, file_symtabs, klass.c_str ());
|
std::vector<symbol *> classes
|
||||||
struct cleanup *old_chain
|
= lookup_prefix_sym (state, file_symtabs, klass.c_str ());
|
||||||
= make_cleanup (VEC_cleanup (symbolp), &classes);
|
if (!classes.empty ())
|
||||||
|
|
||||||
if (!VEC_empty (symbolp, classes))
|
|
||||||
{
|
{
|
||||||
/* Now locate a list of suitable methods named METHOD. */
|
/* Now locate a list of suitable methods named METHOD. */
|
||||||
TRY
|
TRY
|
||||||
{
|
{
|
||||||
find_method (state, file_symtabs,
|
find_method (state, file_symtabs,
|
||||||
klass.c_str (), method.c_str (),
|
klass.c_str (), method.c_str (),
|
||||||
classes, symbols, minsyms);
|
&classes, symbols, minsyms);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If successful, we're done. If NOT_FOUND_ERROR
|
/* If successful, we're done. If NOT_FOUND_ERROR
|
||||||
|
@ -4028,8 +3987,6 @@ find_linespec_symbols (struct linespec_state *state,
|
||||||
}
|
}
|
||||||
END_CATCH
|
END_CATCH
|
||||||
}
|
}
|
||||||
|
|
||||||
do_cleanups (old_chain);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue