Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Doug Evans <dje@google.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] symtab.c: Set "first" to zero.
Date: Fri, 13 Jul 2012 14:57:00 -0000	[thread overview]
Message-ID: <87wr27aeuk.fsf@fleche.redhat.com> (raw)
In-Reply-To: <CADPb22RKufnCNSFXkc3kLX2-Gt9n6ZSQbJugHf5jmWEBdSnM_w@mail.gmail.com>	(Doug Evans's message of "Thu, 12 Jul 2012 14:33:14 -0700")

>>>>> "Doug" == Doug Evans <dje@google.com> writes:

Doug> Any preference?

Not really, I guess.

I didn't realize this way would have to have that weirdness in
output_source_filename.

What do you think of this?
It just makes the cache explicitly managed, and so avoids the confusion
in output_source_filename about what 'first' means.

Tom

2012-07-13  Tom Tromey  <tromey@redhat.com>

	* symtab.c (filename_seen_tab, filename_seen_tab_alloc_size)
	(filename_seen_tab_cur_size): New globals.
	(reset_filename_seen_cache): New function.
	(filename_seen): Remove 'first' parameter.  Update.
	(output_source_filename): Update.
	(sources_info): Call reset_filename_seen_cache.
	(struct add_partial_filename_data) <first>: Remove field.
	(maybe_add_partial_symtab_filename): Update.
	(make_source_files_completion_list): Call
	reset_filename_seen_cache.  Update.

diff --git a/gdb/symtab.c b/gdb/symtab.c
index d83f518..a1444ec 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3105,46 +3105,53 @@ operator_chars (char *p, char **end)
 }
 \f
 
+/* Table of files seen so far.  */
+static const char **filename_seen_tab = NULL;
+/* Allocated size of filename_seen_tab in elements.
+   Start with one 256-byte block (when using GNU malloc.c).
+   24 is the malloc overhead when range checking is in effect.  */
+static int filename_seen_tab_alloc_size = (256 - 24) / sizeof (char *);
+/* Current size of filename_seen_tab in elements.  */
+static int filename_seen_tab_cur_size;
+
+/* Initialize the cache used by filename_seen.  */
+
+static void
+reset_filename_seen_cache (void)
+{
+  if (filename_seen_tab == NULL)
+    filename_seen_tab = xmalloc (filename_seen_tab_alloc_size
+				 * sizeof (*filename_seen_tab));
+  filename_seen_tab_cur_size = 0;
+}
+
 /* If FILE is not already in the table of files, return zero;
    otherwise return non-zero.  Optionally add FILE to the table if ADD
-   is non-zero.  If *FIRST is non-zero, forget the old table
-   contents.  */
+   is non-zero.  */
 
 static int
-filename_seen (const char *file, int add, int *first)
+filename_seen (const char *file, int add)
 {
-  /* Table of files seen so far.  */
-  static const char **tab = NULL;
-  /* Allocated size of tab in elements.
-     Start with one 256-byte block (when using GNU malloc.c).
-     24 is the malloc overhead when range checking is in effect.  */
-  static int tab_alloc_size = (256 - 24) / sizeof (char *);
-  /* Current size of tab in elements.  */
-  static int tab_cur_size;
   const char **p;
 
-  if (*first)
-    {
-      if (tab == NULL)
-	tab = (const char **) xmalloc (tab_alloc_size * sizeof (*tab));
-      tab_cur_size = 0;
-    }
-
-  /* Is FILE in tab?  */
-  for (p = tab; p < tab + tab_cur_size; p++)
+  /* Is FILE in filename_seen_tab?  */
+  for (p = filename_seen_tab;
+       p < filename_seen_tab + filename_seen_tab_cur_size;
+       p++)
     if (filename_cmp (*p, file) == 0)
       return 1;
 
-  /* No; maybe add it to tab.  */
+  /* No; maybe add it to filename_seen_tab.  */
   if (add)
     {
-      if (tab_cur_size == tab_alloc_size)
+      if (filename_seen_tab_cur_size == filename_seen_tab_alloc_size)
 	{
-	  tab_alloc_size *= 2;
-	  tab = (const char **) xrealloc ((char *) tab,
-					  tab_alloc_size * sizeof (*tab));
+	  filename_seen_tab_alloc_size *= 2;
+	  filename_seen_tab = xrealloc (filename_seen_tab,
+					(filename_seen_tab_alloc_size
+					 * sizeof (*filename_seen_tab)));
 	}
-      tab[tab_cur_size++] = file;
+      filename_seen_tab[filename_seen_tab_cur_size++] = file;
     }
 
   return 0;
@@ -3167,7 +3174,7 @@ output_source_filename (const char *name, int *first)
      symtabs; it doesn't hurt to check.  */
 
   /* Was NAME already seen?  */
-  if (filename_seen (name, 1, first))
+  if (filename_seen (name, 1))
     {
       /* Yes; don't print it again.  */
       return;
@@ -3209,6 +3216,7 @@ sources_info (char *ignore, int from_tty)
 
   printf_filtered ("Source files for which symbols have been read in:\n\n");
 
+  reset_filename_seen_cache ();
   first = 1;
   ALL_SYMTABS (objfile, s)
   {
@@ -4543,7 +4551,6 @@ not_interesting_fname (const char *fname)
    map_partial_symbol_filenames.  */
 struct add_partial_filename_data
 {
-  int *first;
   char *text;
   char *word;
   int text_len;
@@ -4560,7 +4567,7 @@ maybe_add_partial_symtab_filename (const char *filename, const char *fullname,
 
   if (not_interesting_fname (filename))
     return;
-  if (!filename_seen (filename, 1, data->first)
+  if (!filename_seen (filename, 1)
       && filename_ncmp (filename, data->text, data->text_len) == 0)
     {
       /* This file matches for a completion; add it to the
@@ -4572,7 +4579,7 @@ maybe_add_partial_symtab_filename (const char *filename, const char *fullname,
       const char *base_name = lbasename (filename);
 
       if (base_name != filename
-	  && !filename_seen (base_name, 1, data->first)
+	  && !filename_seen (base_name, 1)
 	  && filename_ncmp (base_name, data->text, data->text_len) == 0)
 	add_filename_to_list (base_name, data->text, data->word, data->list);
     }
@@ -4588,7 +4595,6 @@ make_source_files_completion_list (char *text, char *word)
 {
   struct symtab *s;
   struct objfile *objfile;
-  int first = 1;
   size_t text_len = strlen (text);
   VEC (char_ptr) *list = NULL;
   const char *base_name;
@@ -4599,12 +4605,13 @@ make_source_files_completion_list (char *text, char *word)
     return list;
 
   back_to = make_cleanup (do_free_completion_list, &list);
+  reset_filename_seen_cache ();
 
   ALL_SYMTABS (objfile, s)
     {
       if (not_interesting_fname (s->filename))
 	continue;
-      if (!filename_seen (s->filename, 1, &first)
+      if (!filename_seen (s->filename, 1)
 	  && filename_ncmp (s->filename, text, text_len) == 0)
 	{
 	  /* This file matches for a completion; add it to the current
@@ -4619,13 +4626,12 @@ make_source_files_completion_list (char *text, char *word)
 	     command do when they parse file names.  */
 	  base_name = lbasename (s->filename);
 	  if (base_name != s->filename
-	      && !filename_seen (base_name, 1, &first)
+	      && !filename_seen (base_name, 1)
 	      && filename_ncmp (base_name, text, text_len) == 0)
 	    add_filename_to_list (base_name, text, word, &list);
 	}
     }
 
-  datum.first = &first;
   datum.text = text;
   datum.word = word;
   datum.text_len = text_len;


  reply	other threads:[~2012-07-13 14:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-10  0:33 Doug Evans
2012-07-10 16:01 ` Tom Tromey
2012-07-10 17:26   ` Doug Evans
2012-07-12 21:33   ` Doug Evans
2012-07-13 14:57     ` Tom Tromey [this message]
2012-07-13 17:39       ` Doug Evans
2012-07-13 17:48         ` Tom Tromey
2012-07-13 18:41           ` Doug Evans

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=87wr27aeuk.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=dje@google.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