return collector.release_symbols ();
}
-/* A std::sort 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. */
+/* Compare pspace A and B based on program space ID. Return 0 if equal,
+ 1 if A->num > B->num, -1 otherwise (modeled on strcmp). */
-static bool
-compare_symbols (const block_symbol &a, const block_symbol &b)
+static int
+compare_pspace (const struct program_space *a, const struct program_space *b)
{
- uintptr_t uia, uib;
+ if (a->num > b->num)
+ return 1;
- uia = (uintptr_t) a.symbol->symtab ()->compunit ()->objfile ()->pspace ();
- uib = (uintptr_t) b.symbol->symtab ()->compunit ()->objfile ()->pspace ();
+ if (a->num < b->num)
+ return -1;
- if (uia < uib)
+ return 0;
+}
+
+/* An std::sort comparison function for symbols. The requirement is that
+ symbols with the same program space end up next to each other. This is for
+ the purpose of iterating over the symbols and doing something once for each
+ program space. */
+
+static bool
+compare_symbols (const block_symbol &a, const block_symbol &b)
+{
+ /* To check for same program space, we could just use a pointer comparison,
+ which gives unstable sorting results. While the assumption is that this
+ doesn't matter, play it safe and compare program space IDs instead. */
+ int cmp
+ = compare_pspace (a.symbol->symtab ()->compunit ()->objfile ()->pspace (),
+ b.symbol->symtab ()->compunit ()->objfile ()->pspace ());
+ if (cmp == -1)
return true;
- if (uia > uib)
+ if (cmp == 1)
return false;
+ uintptr_t uia, uib;
uia = (uintptr_t) a.symbol;
uib = (uintptr_t) b.symbol;
static bool
compare_msymbols (const bound_minimal_symbol &a, const bound_minimal_symbol &b)
{
- uintptr_t uia, uib;
-
- uia = (uintptr_t) a.objfile->pspace ();
- uib = (uintptr_t) a.objfile->pspace ();
-
- if (uia < uib)
+ /* See comment in compare_symbols for use of compare_pspace. */
+ int cmp = compare_pspace (a.objfile->pspace (), a.objfile->pspace ());
+ if (cmp == -1)
return true;
- if (uia > uib)
+ if (cmp == 1)
return false;
+ uintptr_t uia, uib;
uia = (uintptr_t) a.minsym;
uib = (uintptr_t) b.minsym;