From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32486 invoked by alias); 3 Feb 2010 16:08:47 -0000 Received: (qmail 32423 invoked by uid 22791); 3 Feb 2010 16:08:41 -0000 X-SWARE-Spam-Status: No, hits=2.3 required=5.0 tests=AWL,BAYES_00,KAM_STOCKTIP,TVD_STOCK1 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Feb 2010 16:08:34 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 8D86FCB0344 for ; Wed, 3 Feb 2010 17:08:31 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a3HVQCnpC7y8 for ; Wed, 3 Feb 2010 17:08:31 +0100 (CET) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) by mel.act-europe.fr (Postfix) with ESMTP id 78234CB016C for ; Wed, 3 Feb 2010 17:08:31 +0100 (CET) Received: by ulanbator.act-europe.fr (Postfix, from userid 501) id CD008132407E; Wed, 3 Feb 2010 17:08:30 +0100 (CET) Date: Wed, 03 Feb 2010 16:08:00 -0000 From: Tristan Gingold To: gdb-patches@sourceware.org Subject: [RFC] Remove deprecated_sym_private Message-ID: <20100203160830.GA83064@ulanbator.act-europe.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i X-IsSubscribed: yes 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: 2010-02/txt/msg00077.txt.bz2 Hi, I wrote a patch that remove deprecated_sym_private, but I am not sure that it is worth applying it: not sure this is a real improvment, and I think that the private data_key could be shared among all symbol readers. That's the reason why comments are welcome. Simply tested on GNU/Linux x86. I can test it on AIX using the AdaCore testsuite. Tristan. 2010-01-14 Tristan Gingold Remove deprecated_sym_private. * objfiles.h (struct objfile): Remove deprecated_sym_private. * symfile.c (reread_symbols): Remove initialization of deprecated_sym_private. * coffread.c (coff_objfile_data_key): New variable. (coff_symfile_init): Add info variable. Allocate coff_symfile_info on objfile objstack. (coff_symfile_read): Get info from objfile data. (coff_symfile_finish): Remove xfree of coff_symfile_info data. (_initialize_coffread): Set coff_objfile_data_key. * xcoffread.c (xcoff_objfile_data_key): New variable. (get_coff_symfile_info): New function. (process_linenos): Use get_coff_symfile_info instead of deprecated_sym_private. (enter_line_range): Ditto. (xcoff_next_symbol_text): Ditto. (read_xcoff_symtab): Ditto. (read_xcoff_symtab): Ditto. (coff_getfilename): Ditto. (read_symbol): Ditto. (read_symbol_lineno): Ditto. (init_stringtab): Ditto. (swap_sym): Ditto. (scan_xcoff_symtab): Ditto. (xcoff_get_toc_offset): Ditto. (xcoff_initial_scan): Ditto. (xcoff_symfile_init): Allocate coff_symfile_info on objstack. (xcoff_symfile_finish): Do not free coff_symfile_info. (_initialize_xcoffread): Set xcoff_objfile_data_key. --- gdb/coffread.c | 22 +++++++----- gdb/objfiles.h | 11 ------ gdb/symfile.c | 1 - gdb/xcoffread.c | 101 ++++++++++++++++++++++++++---------------------------- 4 files changed, 62 insertions(+), 73 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index ba413ad..d2a72fd 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -59,6 +59,10 @@ struct coff_symfile_info char *stabstrdata; }; +/* The data key for coff_symfile_info. */ + +static const struct objfile_data *coff_objfile_data_key; + /* Translate an external name string into a user-visible name. */ #define EXTERNAL_NAME(string, abfd) \ (string[0] == bfd_get_symbol_leading_char(abfd)? string+1: string) @@ -437,6 +441,8 @@ record_minimal_symbol (struct coff_symbol *cs, CORE_ADDR address, static void coff_symfile_init (struct objfile *objfile) { + struct coff_symfile_info *info; + /* Allocate struct to keep track of stab reading. */ objfile->deprecated_sym_stab_info = (struct dbx_symfile_info *) xmalloc (sizeof (struct dbx_symfile_info)); @@ -445,9 +451,9 @@ coff_symfile_init (struct objfile *objfile) sizeof (struct dbx_symfile_info)); /* Allocate struct to keep track of the symfile */ - objfile->deprecated_sym_private = xmalloc (sizeof (struct coff_symfile_info)); - - memset (objfile->deprecated_sym_private, 0, sizeof (struct coff_symfile_info)); + info = obstack_alloc (&objfile->objfile_obstack, sizeof (*info)); + memset (info, 0, sizeof (*info)); + set_objfile_data (objfile, coff_objfile_data_key, info); /* COFF objects may be reordered, so set OBJF_REORDERED. If we find this causes a significant slowdown in gdb then we could @@ -514,7 +520,8 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) int len; char * target; - info = (struct coff_symfile_info *) objfile->deprecated_sym_private; + info = (struct coff_symfile_info *) objfile_data + (objfile, coff_objfile_data_key); dbxinfo = objfile->deprecated_sym_stab_info; symfile_bfd = abfd; /* Kludge for swap routines */ @@ -665,11 +672,6 @@ coff_new_init (struct objfile *ignore) static void coff_symfile_finish (struct objfile *objfile) { - if (objfile->deprecated_sym_private != NULL) - { - xfree (objfile->deprecated_sym_private); - } - /* Let stabs reader clean up */ stabsread_clear_cache (); @@ -2135,5 +2137,7 @@ static struct sym_fns coff_sym_fns = void _initialize_coffread (void) { + coff_objfile_data_key = register_objfile_data (); + add_symtab_fns (&coff_sym_fns); } diff --git a/gdb/objfiles.h b/gdb/objfiles.h index c689622..334f8d4 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -309,17 +309,6 @@ struct objfile struct dbx_symfile_info *deprecated_sym_stab_info; - /* Hook for information for use by the symbol reader (currently used - for information shared by sym_init and sym_read). It is - typically a pointer to malloc'd memory. The symbol reader's finish - function is responsible for freeing the memory thusly allocated. */ - /* NOTE: cagney/2004-10-23: This has been replaced by per-objfile - data points implemented using "data" and "num_data" below. For - an example of how to use this replacement, see "objfile_data" - in "mips-tdep.c". */ - - void *deprecated_sym_private; - /* Per objfile data-pointers required by other GDB modules. */ /* FIXME: kettenis/20030711: This mechanism could replace deprecated_sym_stab_info and deprecated_sym_private diff --git a/gdb/symfile.c b/gdb/symfile.c index d82f02b..01e7094 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2324,7 +2324,6 @@ reread_symbols (void) objfile->free_psymtabs = NULL; objfile->cp_namespace_symtab = NULL; objfile->msymbols = NULL; - objfile->deprecated_sym_private = NULL; objfile->minimal_symbol_count = 0; memset (&objfile->msymbol_hash, 0, sizeof (objfile->msymbol_hash)); diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index acd7b50..2b7090f 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -150,6 +150,18 @@ struct coff_symfile_info CORE_ADDR toc_offset; }; +/* The data key for coff_symfile_info. */ + +static const struct objfile_data *xcoff_objfile_data_key; + +/* Get coff_symfile_info from OBJFILE. */ + +static struct coff_symfile_info * +get_coff_symfile_info (struct objfile *objfile) +{ + return objfile_data (objfile, xcoff_objfile_data_key); +} + static void bf_notfound_complaint (void) { @@ -552,8 +564,7 @@ process_linenos (CORE_ADDR start, CORE_ADDR end) { int offset, ii; file_ptr max_offset = - ((struct coff_symfile_info *) this_symtab_psymtab->objfile->deprecated_sym_private) - ->max_lineno_offset; + get_coff_symfile_info (this_symtab_psymtab->objfile)->max_lineno_offset; /* subfile structure for the main compilation unit. */ struct subfile main_subfile; @@ -778,9 +789,7 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset, unsigned endoff if (endoffset == 0 && startaddr == 0 && endaddr == 0) return; curoffset = beginoffset; - limit_offset = - ((struct coff_symfile_info *) objfile->deprecated_sym_private) - ->max_lineno_offset; + limit_offset = get_coff_symfile_info (objfile)->max_lineno_offset; if (endoffset != 0) { @@ -899,11 +908,8 @@ xcoff_next_symbol_text (struct objfile *objfile) } else if (symbol.n_sclass & 0x80) { - retval = - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec - + symbol.n_offset; - raw_symbol += - coff_data (objfile->obfd)->local_symesz; + retval = get_coff_symfile_info (objfile)->debugsec + symbol.n_offset; + raw_symbol += coff_data (objfile->obfd)->local_symesz; ++symnum; } else @@ -925,9 +931,9 @@ read_xcoff_symtab (struct partial_symtab *pst) struct objfile *objfile = pst->objfile; bfd *abfd = objfile->obfd; char *raw_auxptr; /* Pointer to first raw aux entry for sym */ - char *strtbl = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl; - char *debugsec = - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec; + struct coff_symfile_info *symfile_info = get_coff_symfile_info (objfile); + char *strtbl = symfile_info->strtbl; + char *debugsec = symfile_info->debugsec; char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF"; struct internal_syment symbol[1]; @@ -968,13 +974,10 @@ read_xcoff_symtab (struct partial_symtab *pst) start_symtab (filestring, (char *) NULL, file_start_addr); record_debugformat (debugfmt); symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum; - max_symnum = - symnum + ((struct symloc *) pst->read_symtab_private)->numsyms; + max_symnum = symnum + ((struct symloc *) pst->read_symtab_private)->numsyms; first_object_file_end = 0; - raw_symbol = - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl - + symnum * local_symesz; + raw_symbol = get_coff_symfile_info (objfile)->symtbl + symnum * local_symesz; while (symnum < max_symnum) { @@ -1595,8 +1598,7 @@ coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile) static char buffer[BUFSIZ]; if (aux_entry->x_file.x_n.x_zeroes == 0) - strcpy (buffer, - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl + strcpy (buffer, get_coff_symfile_info (objfile)->strtbl + aux_entry->x_file.x_n.x_offset); else { @@ -1610,10 +1612,10 @@ coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile) static void read_symbol (struct internal_syment *symbol, int symno) { - int nsyms = - ((struct coff_symfile_info *) this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl_num_syms; - char *stbl = - ((struct coff_symfile_info *) this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl; + struct coff_symfile_info *symfile_info = + get_coff_symfile_info (this_symtab_psymtab->objfile); + int nsyms = symfile_info->symtbl_num_syms; + char *stbl = symfile_info->symtbl; if (symno < 0 || symno >= nsyms) { complaint (&symfile_complaints, _("Invalid symbol offset")); @@ -1647,8 +1649,7 @@ read_symbol_lineno (int symno) struct objfile *objfile = this_symtab_psymtab->objfile; int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd); - struct coff_symfile_info *info = - (struct coff_symfile_info *)objfile->deprecated_sym_private; + struct coff_symfile_info *info = get_coff_symfile_info (objfile); int nsyms = info->symtbl_num_syms; char *stbl = info->symtbl; char *strtbl = info->strtbl; @@ -1850,8 +1851,12 @@ xcoff_new_init (struct objfile *objfile) static void xcoff_symfile_init (struct objfile *objfile) { + struct coff_symfile_info *data; + /* Allocate struct to keep track of the symfile */ - objfile->deprecated_sym_private = xmalloc (sizeof (struct coff_symfile_info)); + data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); + memset (data, 0, sizeof (*data)); + set_objfile_data (objfile, xcoff_objfile_data_key, data); /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we find this causes a significant slowdown in gdb then we could @@ -1869,11 +1874,6 @@ xcoff_symfile_init (struct objfile *objfile) static void xcoff_symfile_finish (struct objfile *objfile) { - if (objfile->deprecated_sym_private != NULL) - { - xfree (objfile->deprecated_sym_private); - } - /* Start with a fresh include table for the next objfile. */ if (inclTable) { @@ -1891,8 +1891,9 @@ init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile) int val; unsigned char lengthbuf[4]; char *strtbl; + struct coff_symfile_info *info = get_coff_symfile_info (objfile); - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl = NULL; + info->strtbl = NULL; if (bfd_seek (abfd, offset, SEEK_SET) < 0) error (_("cannot seek to string table in %s: %s"), @@ -1911,7 +1912,7 @@ init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile) as long as we have its symbol table around. */ strtbl = (char *) obstack_alloc (&objfile->objfile_obstack, length); - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl = strtbl; + info->strtbl = strtbl; /* Copy length buffer, the first byte is usually zero and is used for stabs with a name length of zero. */ @@ -2101,13 +2102,11 @@ swap_sym (struct internal_syment *symbol, union internal_auxent *aux, } else if (symbol->n_sclass & 0x80) { - *name = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec - + symbol->n_offset; + *name = get_coff_symfile_info (objfile)->debugsec + symbol->n_offset; } else { - *name = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl - + symbol->n_offset; + *name = get_coff_symfile_info (objfile)->strtbl + symbol->n_offset; } ++*symnump; *raw += coff_data (objfile->obfd)->local_symesz; @@ -2133,6 +2132,7 @@ static void scan_xcoff_symtab (struct objfile *objfile) { struct gdbarch *gdbarch = get_objfile_arch (objfile); + struct coff_symfile_info *info = get_coff_symfile_info (objfle); CORE_ADDR toc_offset = 0; /* toc offset value in data section. */ char *filestring = NULL; @@ -2183,8 +2183,8 @@ scan_xcoff_symtab (struct objfile *objfile) abfd = objfile->obfd; next_symbol_text_func = xcoff_next_symbol_text; - sraw_symbol = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl; - nsyms = ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl_num_syms; + sraw_symbol = info->symtbl; + nsyms = info->symtbl_num_syms; ssymnum = 0; while (ssymnum < nsyms) { @@ -2843,7 +2843,7 @@ scan_xcoff_symtab (struct objfile *objfile) If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain this information would be file auxiliary header. */ - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->toc_offset = toc_offset; + info->toc_offset = toc_offset; } /* Return the toc offset value for a given objfile. */ @@ -2852,7 +2852,7 @@ CORE_ADDR xcoff_get_toc_offset (struct objfile *objfile) { if (objfile) - return ((struct coff_symfile_info *) objfile->deprecated_sym_private)->toc_offset; + return get_coff_symfile_info (objfile)->toc_offset; return 0; } @@ -2874,11 +2874,10 @@ xcoff_initial_scan (struct objfile *objfile, int symfile_flags) int num_symbols; /* # of symbols */ file_ptr symtab_offset; /* symbol table and */ file_ptr stringtab_offset; /* string table file offsets */ - struct coff_symfile_info *info; + struct coff_symfile_info *info = get_coff_symfile_info (objfile); char *name; unsigned int size; - info = (struct coff_symfile_info *) objfile->deprecated_sym_private; symfile_bfd = abfd = objfile->obfd; name = objfile->name; @@ -2919,8 +2918,7 @@ xcoff_initial_scan (struct objfile *objfile, int symfile_flags) } } } - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec = - debugsec; + info->debugsec = debugsec; } } @@ -2931,13 +2929,10 @@ xcoff_initial_scan (struct objfile *objfile, int symfile_flags) error (_("Error reading symbols from %s: %s"), name, bfd_errmsg (bfd_get_error ())); size = coff_data (abfd)->local_symesz * num_symbols; - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl = - obstack_alloc (&objfile->objfile_obstack, size); - ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl_num_syms = - num_symbols; + info->symtbl = obstack_alloc (&objfile->objfile_obstack, size); + info->symtbl_num_syms = num_symbols; - val = bfd_bread (((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl, - size, abfd); + val = bfd_bread (info->symtbl, size, abfd); if (val != size) perror_with_name (_("reading symbol table")); @@ -3045,5 +3040,7 @@ extern initialize_file_ftype _initialize_xcoffread; void _initialize_xcoffread (void) { + xcoff_objfile_data_key = register_objfile_data (); + add_symtab_fns (&xcoff_sym_fns); } -- 1.6.2