From 434d2d4f74d34f297cdeb511d3a6cb5026da0c1c Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Mon, 11 Feb 2002 03:21:53 +0000 Subject: [PATCH] 2002-02-10 Daniel Jacobowitz * symtab.c (compare_search_syms): New function. (sort_search_symbols): New function. (search_symbols): Sort symbols after searching rather than before. 2002-02-10 Daniel Jacobowitz * generic/gdbtk-cmds.c (gdb_listfuncs): Don't call BLOCK_SHOULD_SORT. * library/browserwin.itb (BrowserWin::_fill_funcs_combo): Sort the output of gdb_listfuncs. --- gdb/ChangeLog | 7 +++++ gdb/symtab.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 69a43d92dc..fbba769fb6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2002-02-10 Daniel Jacobowitz + + * symtab.c (compare_search_syms): New function. + (sort_search_symbols): New function. + (search_symbols): Sort symbols after searching rather than + before. + 2002-02-10 Andrew Cagney * NEWS: Linux -> GNU/Linux. diff --git a/gdb/symtab.c b/gdb/symtab.c index 18bea05e39..743253f1d9 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2406,6 +2406,52 @@ make_cleanup_free_search_symbols (struct symbol_search *symbols) return make_cleanup (do_free_search_symbols_cleanup, symbols); } +/* Helper function for sort_search_symbols and qsort. Can only + sort symbols, not minimal symbols. */ +static int +compare_search_syms (const void *sa, const void *sb) +{ + struct symbol_search **sym_a = (struct symbol_search **) sa; + struct symbol_search **sym_b = (struct symbol_search **) sb; + + return strcmp (SYMBOL_SOURCE_NAME ((*sym_a)->symbol), + SYMBOL_SOURCE_NAME ((*sym_b)->symbol)); +} + +/* Sort the ``nfound'' symbols in the list after prevtail. Leave + prevtail where it is, but update its next pointer to point to + the first of the sorted symbols. */ +static struct symbol_search * +sort_search_symbols (struct symbol_search *prevtail, int nfound) +{ + struct symbol_search **symbols, *symp, *old_next; + int i; + + symbols = (struct symbol_search **) xmalloc (sizeof (struct symbol_search *) + * nfound); + symp = prevtail->next; + for (i = 0; i < nfound; i++) + { + symbols[i] = symp; + symp = symp->next; + } + /* Generally NULL. */ + old_next = symp; + + qsort (symbols, nfound, sizeof (struct symbol_search *), + compare_search_syms); + + symp = prevtail; + for (i = 0; i < nfound; i++) + { + symp->next = symbols[i]; + symp = symp->next; + } + symp->next = old_next; + + free (symbols); + return symp; +} /* Search the symbol table for matches to the regular expression REGEXP, returning the results in *MATCHES. @@ -2418,6 +2464,9 @@ make_cleanup_free_search_symbols (struct symbol_search *symbols) and constants (enums) free_search_symbols should be called when *MATCHES is no longer needed. + + The results are sorted locally; each symtab's global and static blocks are + separately alphabetized. */ void search_symbols (char *regexp, namespace_enum kind, int nfiles, char *files[], @@ -2607,10 +2656,9 @@ search_symbols (char *regexp, namespace_enum kind, int nfiles, char *files[], if (bv != prev_bv) for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) { + struct symbol_search *prevtail = tail; + int nfound = 0; b = BLOCKVECTOR_BLOCK (bv, i); - /* Skip the sort if this block is always sorted. */ - if (!BLOCK_SHOULD_SORT (b)) - sort_block_syms (b); for (j = 0; j < BLOCK_NSYMS (b); j++) { QUIT; @@ -2632,14 +2680,27 @@ search_symbols (char *regexp, namespace_enum kind, int nfiles, char *files[], psr->msymbol = NULL; psr->next = NULL; if (tail == NULL) - { - sr = psr; - old_chain = make_cleanup_free_search_symbols (sr); - } + sr = psr; else tail->next = psr; tail = psr; + nfound ++; + } + } + if (nfound > 0) + { + if (prevtail == NULL) + { + struct symbol_search dummy; + + dummy.next = sr; + tail = sort_search_symbols (&dummy, nfound); + sr = dummy.next; + + old_chain = make_cleanup_free_search_symbols (sr); } + else + tail = sort_search_symbols (prevtail, nfound); } } prev_bv = bv; -- 2.34.1