This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] symtab.c: Set "first" to zero.


>>>>> "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)
 }
 
 
+/* 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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]