From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22535 invoked by alias); 13 Jul 2012 14:57:59 -0000 Received: (qmail 22521 invoked by uid 22791); 13 Jul 2012 14:57:57 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Jul 2012 14:57:26 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6DEvPKq013503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 13 Jul 2012 10:57:25 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6DEvNY0024325 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 13 Jul 2012 10:57:23 -0400 From: Tom Tromey To: Doug Evans Cc: gdb-patches@sourceware.org Subject: Re: [RFA] symtab.c: Set "first" to zero. References: <20120710003324.100001E13A1@ruffy2.mtv.corp.google.com> <87629vip17.fsf@fleche.redhat.com> Date: Fri, 13 Jul 2012 14:57:00 -0000 In-Reply-To: (Doug Evans's message of "Thu, 12 Jul 2012 14:33:14 -0700") Message-ID: <87wr27aeuk.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-07/txt/msg00178.txt.bz2 >>>>> "Doug" == Doug Evans 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 * 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) : 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;