From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2064 invoked by alias); 14 May 2013 16:03:40 -0000 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 Received: (qmail 2027 invoked by uid 89); 14 May 2013 16:03:39 -0000 X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_00,KAM_STOCKTIP,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,RP_MATCHES_RCVD,SPF_PASS,TW_BJ,TW_DB autolearn=no version=3.3.1 Received: from mail-vc0-f202.google.com (HELO mail-vc0-f202.google.com) (209.85.220.202) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 14 May 2013 16:03:38 +0000 Received: by mail-vc0-f202.google.com with SMTP id gf12so70899vcb.5 for ; Tue, 14 May 2013 09:03:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:subject:date:message-id:mime-version :content-type:x-gm-message-state; bh=ZOmR5Hpxty+mmncP/bY6tXLVgjThBDmwJjamxsjPZJc=; b=MeHkz0v1dgVU2jrJ27kjicpo6dT+yy6cQIi8iJQhk2eC/oPdhFCdE5h4foJ5ThXIFY 3xDmwNloUYUAreIXm98Zzowdxtt0RkG+L19p6nLATc5EbzNFrFO8h3QHvIWmWkWVkniE YajAffe47kOzUusu+THkOuDwueqTOsXWSBMIfWw5uL4oUdFjIBXIyOYnhs76RAy+4N+p uQoq3JkMVqyNzqisVrz4Frbu1yPRmUNICyBUpkaUlM4ayX8cX7UgmDuW68dcWXgboKbL 0+riy8dKmDOj5eOxwTCjdvYNXa4lCaLB8Kil189JILno/tTEcZXa+5YwPeBGJBSo8ay+ jnUA== X-Received: by 10.236.120.166 with SMTP id p26mr16608638yhh.57.1368547416810; Tue, 14 May 2013 09:03:36 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id s48si997371yhe.6.2013.05.14.09.03.36 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2013 09:03:36 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 6B2F631C2ED for ; Tue, 14 May 2013 09:03:36 -0700 (PDT) From: Doug Evans To: gdb-patches@sourceware.org Subject: [RFA] buildsym.c cleanup Date: Tue, 14 May 2013 16:03:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQlf2QQVNhh4jgiGCAstMP5P5Cd5JjN56iwkdHvvMp0ketQbXLPCRLnQ+c8v9qxQ4IIa4bb1Os3FKpUSv1Twa7HnGwol5aMDrVkxfkpAgjpkOEviK4haf8RRIoCriUUPNIE5fm7p2mJB9fxTfJ4O0hikO7RGMQw4/Rp2MwnXoQBOZcNSGVE8MBQxOXtLfqeS4nAtV+uLaDqEnCh7NJTxiygbyldhVQSTfNYVjU/kHe81PB/s2tc= X-SW-Source: 2013-05/txt/msg00473.txt.bz2 Hi. While working on making reading of debug info more interruptible I came across a bit of cleanup that can be done first. This patch removes some publically used globals and either moves them into buildsym.c or into their respective debug info readers. Regression tested on amd64-linux, and a second time with -gstabs. I didn't check coff though, however the change is mechanical. Can someone test this on coff, or is this ok to check in now? [I think there's more that can be done here, but I think this can go in now.] 2013-05-14 Doug Evans * buildsym.c (subfile_stack): Move here from buildsym.h. (pending_macros): Ditto. (get_macro_table): New function. (buildsym_init): Initialize subfile_stack. * coffread.c (type_vector,type_vector_length): Moved here from buildsym.h. (INITIAL_TYPE_VECTOR_LENGTH): Ditto. (coff_symtab_read): Use it. * dbxread.c (read_ofile_symtab): Delete init of subfile_stack. * dwarf2read.c (macro_start_file): Replace uses of pending_macros with call to get_macro_table. * stabsread.c (type_vector,type_vector_length): Moved here from buildsym.h. (INITIAL_TYPE_VECTOR_LENGTH): Ditto. * buildsym.h (get_macro_table): Declare. Index: buildsym.c =================================================================== RCS file: /cvs/src/src/gdb/buildsym.c,v retrieving revision 1.108 diff -u -p -r1.108 buildsym.c --- buildsym.c 1 Apr 2013 12:48:03 -0000 1.108 +++ buildsym.c 14 May 2013 15:38:50 -0000 @@ -102,13 +102,24 @@ struct pending_block associated symtab. */ static struct pending_block *pending_blocks; - + +struct subfile_stack + { + struct subfile_stack *next; + char *name; + }; + +static struct subfile_stack *subfile_stack; + +/* The macro table for the compilation unit whose symbols we're + currently reading. All the symtabs for the CU will point to this. */ +static struct macro_table *pending_macros; + static int compare_line_numbers (const void *ln1p, const void *ln2p); static void record_pending_block (struct objfile *objfile, struct block *block, struct pending_block *opblock); - /* Initial sizes of data structures. These are realloc'd larger if needed, and realloc'd down to the size actually used, when @@ -825,6 +836,19 @@ compare_line_numbers (const void *ln1p, return ln1->line - ln2->line; } +/* Return the macro table. + Initialize it if this is the first use. */ + +struct macro_table * +get_macro_table (struct objfile *objfile, const char *comp_dir) +{ + if (! pending_macros) + pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack, + objfile->per_bfd->macro_cache, + comp_dir); + return pending_macros; +} + /* Start a new symtab for a new source file. Called, for example, when a stabs symbol of type N_SO is seen, or when a DWARF TAG_compile_unit DIE is seen. It indicates the start of data for @@ -1538,6 +1562,7 @@ buildsym_init (void) pending_blocks = NULL; pending_macros = NULL; using_directives = NULL; + subfile_stack = NULL; /* We shouldn't have any address map at this point. */ gdb_assert (! pending_addrmap); Index: buildsym.h =================================================================== RCS file: /cvs/src/src/gdb/buildsym.h,v retrieving revision 1.39 diff -u -p -r1.39 buildsym.h --- buildsym.h 21 Jan 2013 18:05:13 -0000 1.39 +++ buildsym.h 14 May 2013 15:38:50 -0000 @@ -173,37 +173,12 @@ EXTERN int within_function; -struct subfile_stack - { - struct subfile_stack *next; - char *name; - }; - -EXTERN struct subfile_stack *subfile_stack; - #define next_symbol_text(objfile) (*next_symbol_text_func)(objfile) /* Function to invoke get the next symbol. Return the symbol name. */ EXTERN char *(*next_symbol_text_func) (struct objfile *); -/* Vector of types defined so far, indexed by their type numbers. - Used for both stabs and coff. (In newer sun systems, dbx uses a - pair of numbers in parens, as in "(SUBFILENUM,NUMWITHINSUBFILE)". - Then these numbers must be translated through the type_translations - hash table to get the index into the type vector.) */ - -EXTERN struct type **type_vector; - -/* Number of elements allocated for type_vector currently. */ - -EXTERN int type_vector_length; - -/* Initial size of type vector. Is realloc'd larger if needed, and - realloc'd down to the size actually used, when completed. */ - -#define INITIAL_TYPE_VECTOR_LENGTH 160 - extern void add_symbol_to_list (struct symbol *symbol, struct pending **listhead); @@ -296,10 +271,10 @@ extern void set_last_source_file (const extern const char *get_last_source_file (void); -/* The macro table for the compilation unit whose symbols we're - currently reading. All the symtabs for this CU will point to - this. */ -EXTERN struct macro_table *pending_macros; +/* Return the macro table. */ + +extern struct macro_table *get_macro_table (struct objfile *objfile, + const char *comp_dir); #undef EXTERN Index: coffread.c =================================================================== RCS file: /cvs/src/src/gdb/coffread.c,v retrieving revision 1.145 diff -u -p -r1.145 coffread.c --- coffread.c 8 Apr 2013 20:13:21 -0000 1.145 +++ coffread.c 14 May 2013 15:59:02 -0000 @@ -146,6 +146,19 @@ struct coff_symbol unsigned int c_type; }; +/* Vector of types defined so far, indexed by their type numbers. */ + +static struct type **type_vector; + +/* Number of elements allocated for type_vector currently. */ + +static int type_vector_length; + +/* Initial size of type vector. Is realloc'd larger if needed, and + realloc'd down to the size actually used, when completed. */ + +#define INITIAL_TYPE_VECTOR_LENGTH 160 + extern void stabsread_clear_cache (void); static struct type *coff_read_struct_type (int, int, int, @@ -787,7 +800,7 @@ coff_symtab_read (long symtab_offset, un if (type_vector) /* Get rid of previous one. */ xfree (type_vector); - type_vector_length = 160; + type_vector_length = INITIAL_TYPE_VECTOR_LENGTH; type_vector = (struct type **) xmalloc (type_vector_length * sizeof (struct type *)); memset (type_vector, 0, type_vector_length * sizeof (struct type *)); Index: dbxread.c =================================================================== RCS file: /cvs/src/src/gdb/dbxread.c,v retrieving revision 1.146 diff -u -p -r1.146 dbxread.c --- dbxread.c 6 May 2013 19:15:17 -0000 1.146 +++ dbxread.c 14 May 2013 15:38:50 -0000 @@ -2528,7 +2528,6 @@ read_ofile_symtab (struct objfile *objfi section_offsets = pst->section_offsets; dbxread_objfile = objfile; - subfile_stack = NULL; stringtab_global = DBX_STRINGTAB (objfile); set_last_source_file (NULL); Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.798 diff -u -p -r1.798 dwarf2read.c --- dwarf2read.c 13 May 2013 16:56:09 -0000 1.798 +++ dwarf2read.c 14 May 2013 15:38:50 -0000 @@ -18540,19 +18540,16 @@ macro_start_file (int file, int line, /* File name relative to the compilation directory of this source file. */ char *file_name = file_file_name (file, lh); - /* We don't create a macro table for this compilation unit - at all until we actually get a filename. */ - if (! pending_macros) - pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack, - objfile->per_bfd->macro_cache, - comp_dir); - if (! current_file) { + /* Note: We don't create a macro table for this compilation unit + at all until we actually get a filename. */ + struct macro_table *macro_table = get_macro_table (objfile, comp_dir); + /* If we have no current file, then this must be the start_file directive for the compilation unit's main source file. */ - current_file = macro_set_main (pending_macros, file_name); - macro_define_special (pending_macros); + current_file = macro_set_main (macro_table, file_name); + macro_define_special (macro_table); } else current_file = macro_include (current_file, line, file_name); Index: stabsread.c =================================================================== RCS file: /cvs/src/src/gdb/stabsread.c,v retrieving revision 1.155 diff -u -p -r1.155 stabsread.c --- stabsread.c 8 Apr 2013 20:18:11 -0000 1.155 +++ stabsread.c 14 May 2013 15:38:50 -0000 @@ -207,6 +207,23 @@ static int noname_undefs_length; if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \ *(pp) = next_symbol_text (objfile); \ } while (0) + +/* Vector of types defined so far, indexed by their type numbers. + (In newer sun systems, dbx uses a pair of numbers in parens, + as in "(SUBFILENUM,NUMWITHINSUBFILE)". + Then these numbers must be translated through the type_translations + hash table to get the index into the type vector.) */ + +static struct type **type_vector; + +/* Number of elements allocated for type_vector currently. */ + +static int type_vector_length; + +/* Initial size of type vector. Is realloc'd larger if needed, and + realloc'd down to the size actually used, when completed. */ + +#define INITIAL_TYPE_VECTOR_LENGTH 160 /* Look up a dbx type-number pair. Return the address of the slot