public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] Use FILENAME_CMP to compare filenames in compare_search_syms.
Date: Tue, 01 Oct 2013 09:54:00 -0000	[thread overview]
Message-ID: <524A9BCF.90502@redhat.com> (raw)
In-Reply-To: <1380618427-27814-1-git-send-email-brobecker@adacore.com>

On 10/01/2013 10:07 AM, Joel Brobecker wrote:
> Hello,
> 
> While working on an unrelated issue, I noticed that two symbols were
> sorted differently on Windows, compared to the other Unix platforms.
> I tracked it down to compare_search_syms which compares filenames
> using a plain strcmp instead of FILENAME_CMP.
> 
> Not sure how to create a testcase...
> 
> gdb/ChangeLog:
> 
>         * symtab.c (compare_search_syms): Use FILENAME_CMP instead of
>         strcmp to compare two symtab filenames.
> 
> Tested on x86-windows and x86_64-linux, no regression.
> OK to apply?

I'd say that use of FILENAME_CMP instead of strcmp is an obvious change.

However, this is not complete.  This function is called by:

/* Sort the NFOUND symbols in list FOUND and remove duplicates.
   The duplicates are freed, and the new list is returned in
   *NEW_HEAD, *NEW_TAIL.  */

static void
sort_search_symbols_remove_dups (struct symbol_search *found, int nfound,
				 struct symbol_search **new_head,
				 struct symbol_search **new_tail)
{
...
  qsort (symbols, nfound, sizeof (struct symbol_search *),
	 compare_search_syms);

So this is sorting symbols, to then walk over the sorted list
linearly and remove dups.  That happens right afterwards:

  /* Collapse out the dups.  */
  for (i = 1, j = 1; i < nfound; ++i)
    {
      if (! search_symbols_equal (symbols[j - 1], symbols[i]))
	symbols[j++] = symbols[i];
      else
	xfree (symbols[i]);
    }

So the compare_search_syms and search_symbols_equal predicates
_must_ agree.  And, lo, search_symbols_equal also has that strcmp
that would need adjustment as well:

 static int
 search_symbols_equal (const struct symbol_search *a,
 		      const struct symbol_search *b)
 {
   return (strcmp (a->symtab->filename, b->symtab->filename) == 0
 	  && a->block == b->block
 	  && strcmp (SYMBOL_PRINT_NAME (a->symbol),
 		     SYMBOL_PRINT_NAME (b->symbol)) == 0);
 }


But really, so that this sort of out-of-sync bugs doesn't
happen, it'd be better if search_symbols_equal were reimplemented
in terms of compare_search_syms or even be eliminated.

-- 
Pedro Alves

  reply	other threads:[~2013-10-01  9:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-01  9:07 Joel Brobecker
2013-10-01  9:54 ` Pedro Alves [this message]
2013-10-01 12:30   ` Joel Brobecker
2013-10-01 15:14     ` Pedro Alves
2013-10-02  9:24       ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=524A9BCF.90502@redhat.com \
    --to=palves@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).