2002-02-10 Daniel Jacobowitz <drow@mvista.com>
authorDaniel Jacobowitz <drow@false.org>
Mon, 11 Feb 2002 03:21:53 +0000 (03:21 +0000)
committerDaniel Jacobowitz <drow@false.org>
Mon, 11 Feb 2002 03:21:53 +0000 (03:21 +0000)
        * 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  <drow@mvista.com>

        * 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
gdb/symtab.c

index 69a43d92dcba74fa21e591a939b26d4eb55cfc92..fbba769fb69d09b0784a0be9046270f9fc424aa5 100644 (file)
@@ -1,3 +1,10 @@
+2002-02-10  Daniel Jacobowitz  <drow@mvista.com>
+
+       * 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  <ac131313@redhat.com>
 
        * NEWS: Linux -> GNU/Linux.
index 18bea05e392fdee25a787205d7a000b9b1cac736..743253f1d9c67979f7cba60946eb5f25bd11d146 100644 (file)
@@ -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;
This page took 0.043148 seconds and 4 git commands to generate.