From patchwork Thu Nov 13 12:54:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 3708 Received: (qmail 12610 invoked by alias); 13 Nov 2014 12:56:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 12584 invoked by uid 89); 13 Nov 2014 12:56:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f173.google.com Received: from mail-pd0-f173.google.com (HELO mail-pd0-f173.google.com) (209.85.192.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 13 Nov 2014 12:55:59 +0000 Received: by mail-pd0-f173.google.com with SMTP id v10so14431963pde.18 for ; Thu, 13 Nov 2014 04:55:57 -0800 (PST) X-Received: by 10.66.236.163 with SMTP id uv3mr2490503pac.136.1415883341158; Thu, 13 Nov 2014 04:55:41 -0800 (PST) Received: from sspiff.org (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by mx.google.com with ESMTPSA id v15sm24798670pdj.96.2014.11.13.04.55.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Nov 2014 04:55:40 -0800 (PST) Message-ID: <5464aa4c.2f25460a.37cf.ffffa274@mx.google.com> Received: by sspiff.org (sSMTP sendmail emulation); Thu, 13 Nov 2014 04:54:48 -0800 Date: Thu, 13 Nov 2014 04:54:48 -0800 From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH 20/21] struct symtab split part 2: symfile-debug.c symfile.c symfile.h X-IsSubscribed: yes This patch contains the changes to symfile-debug.c, symfile.c, symfile.h. Full ChangeLog: https://sourceware.org/ml/gdb-patches/2014-11/msg00233.html 2014-11-12 Doug Evans * symfile-debug.c (debug_qf_find_last_source_symtab): Change result type to "struct compunit_symtab *". All callers updated. (debug_qf_lookup_symbol): Ditto. (debug_qf_find_pc_sect_compunit_symtab): Renamed from debug_qf_find_pc_sect_symtab, change result type to "struct compunit_symtab *". All callers updated. * symfile.c (allocate_symtab): Delete objfile argument. New argument cust. (allocate_compunit_symtab): New function. (add_compunit_symtab_to_objfile): New function. * symfile.h (struct quick_symbol_functions) : Change result type to "struct compunit_symtab *". All uses updated. : Renamed from find_pc_sect_symtab. Change result type to "struct compunit_symtab *". All uses updated. diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 170ba3a..8bca5b2 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -151,13 +151,13 @@ debug_qf_map_symtabs_matching_filename (struct objfile *objfile, return retval; } -static struct symtab * +static struct compunit_symtab * debug_qf_lookup_symbol (struct objfile *objfile, int kind, const char *name, domain_enum domain) { const struct debug_sym_fns_data *debug_data = objfile_data (objfile, symfile_debug_objfile_data_key); - struct symtab *retval; + struct compunit_symtab *retval; fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (%s, %d, \"%s\", %s)\n", @@ -168,7 +168,9 @@ debug_qf_lookup_symbol (struct objfile *objfile, int kind, const char *name, domain); fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n", - retval ? debug_symtab_name (retval) : "NULL"); + retval + ? debug_symtab_name (compunit_primary_filetab (retval)) + : "NULL"); return retval; } @@ -306,31 +308,35 @@ debug_qf_expand_symtabs_matching kind, data); } -static struct symtab * -debug_qf_find_pc_sect_symtab (struct objfile *objfile, - struct bound_minimal_symbol msymbol, - CORE_ADDR pc, - struct obj_section *section, - int warn_if_readin) +static struct compunit_symtab * +debug_qf_find_pc_sect_compunit_symtab (struct objfile *objfile, + struct bound_minimal_symbol msymbol, + CORE_ADDR pc, + struct obj_section *section, + int warn_if_readin) { const struct debug_sym_fns_data *debug_data = objfile_data (objfile, symfile_debug_objfile_data_key); - struct symtab *retval; + struct compunit_symtab *retval; fprintf_filtered (gdb_stdlog, - "qf->find_pc_sect_symtab (%s, %s, %s, %s, %d)\n", + "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n", debug_objfile_name (objfile), host_address_to_string (msymbol.minsym), hex_string (pc), host_address_to_string (section), warn_if_readin); - retval = debug_data->real_sf->qf->find_pc_sect_symtab (objfile, msymbol, - pc, section, - warn_if_readin); + retval + = debug_data->real_sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol, + pc, section, + warn_if_readin); - fprintf_filtered (gdb_stdlog, "qf->find_pc_sect_symtab (...) = %s\n", - retval ? debug_symtab_name (retval) : "NULL"); + fprintf_filtered (gdb_stdlog, + "qf->find_pc_sect_compunit_symtab (...) = %s\n", + retval + ? debug_symtab_name (compunit_primary_filetab (retval)) + : "NULL"); return retval; } @@ -368,7 +374,7 @@ static const struct quick_symbol_functions debug_sym_quick_functions = debug_qf_expand_symtabs_with_fullname, debug_qf_map_matching_symbols, debug_qf_expand_symtabs_matching, - debug_qf_find_pc_sect_symtab, + debug_qf_find_pc_sect_compunit_symtab, debug_qf_map_symbol_filenames }; diff --git a/gdb/symfile.c b/gdb/symfile.c index 01ff6ae..29877ec 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2641,7 +2641,7 @@ reread_symbols (void) objfile->psymbol_cache = psymbol_bcache_init (); obstack_free (&objfile->objfile_obstack, 0); objfile->sections = NULL; - objfile->symtabs = NULL; + objfile->compunit_symtabs = NULL; objfile->psymtabs = NULL; objfile->psymtabs_addrmap = NULL; objfile->free_psymtabs = NULL; @@ -2918,38 +2918,20 @@ deduce_language_from_filename (const char *filename) return language_unknown; } -/* allocate_symtab: - - Allocate and partly initialize a new symbol table. Return a pointer - to it. error() if no space. - - Caller must set these fields: - LINETABLE(symtab) - symtab->blockvector - symtab->dirname - symtab->free_code - symtab->free_ptr - */ +/* Allocate and initialize a new symbol table. + CUST is from the result of allocate_compunit_symtab. */ struct symtab * -allocate_symtab (const char *filename, struct objfile *objfile) +allocate_symtab (struct compunit_symtab *cust, const char *filename) { - struct symtab *symtab; + struct objfile *objfile = cust->objfile; + struct symtab *symtab + = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symtab); - symtab = (struct symtab *) - obstack_alloc (&objfile->objfile_obstack, sizeof (struct symtab)); - memset (symtab, 0, sizeof (*symtab)); symtab->filename = bcache (filename, strlen (filename) + 1, objfile->per_bfd->filename_cache); symtab->fullname = NULL; symtab->language = deduce_language_from_filename (filename); - symtab->debugformat = "unknown"; - - /* Hook it to the objfile it comes from. */ - - SYMTAB_OBJFILE (symtab) = objfile; - symtab->next = objfile->symtabs; - objfile->symtabs = symtab; /* This can be very verbose with lots of headers. Only print at higher debug levels. */ @@ -2973,7 +2955,64 @@ allocate_symtab (const char *filename, struct objfile *objfile) host_address_to_string (symtab), filename); } - return (symtab); + /* Add it to CUST's list of symtabs. */ + if (cust->filetabs == NULL) + { + cust->filetabs = symtab; + cust->last_filetab = symtab; + } + else + { + cust->last_filetab->next = symtab; + cust->last_filetab = symtab; + } + + /* Backlink to the containing compunit symtab. */ + symtab->compunit_symtab = cust; + + return symtab; +} + +/* Allocate and initialize a new compunit. + NAME is the name of the main source file, if there is one, or some + descriptive text if there are no source files. */ + +struct compunit_symtab * +allocate_compunit_symtab (struct objfile *objfile, const char *name) +{ + struct compunit_symtab *cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, + struct compunit_symtab); + const char *saved_name; + + cu->objfile = objfile; + + /* The name we record here is only for display/debugging purposes. + Just save the basename to avoid path issues (too long for display, + relative vs absolute, etc.). */ + saved_name = lbasename (name); + cu->name = obstack_copy0 (&objfile->objfile_obstack, saved_name, + strlen (saved_name)); + + COMPUNIT_DEBUGFORMAT (cu) = "unknown"; + + if (symtab_create_debug) + { + fprintf_unfiltered (gdb_stdlog, + "Created compunit symtab %s for %s.\n", + host_address_to_string (cu), + cu->name); + } + + return cu; +} + +/* Hook CU to the objfile it comes from. */ + +void +add_compunit_symtab_to_objfile (struct compunit_symtab *cu) +{ + cu->next = cu->objfile->compunit_symtabs; + cu->objfile->compunit_symtabs = cu; } diff --git a/gdb/symfile.h b/gdb/symfile.h index f56aff3..1e8c230 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -193,13 +193,13 @@ struct quick_symbol_functions symbols. NAME is the name of the symbol to look for. DOMAIN indicates what sort of symbol to search for. - Returns the newly-expanded symbol table in which the symbol is + Returns the newly-expanded compunit in which the symbol is defined, or NULL if no such symbol table exists. If OBJFILE - contains !TYPE_OPAQUE symbol prefer its symtab. If it contains - only TYPE_OPAQUE symbol(s), return at least that symtab. */ - struct symtab *(*lookup_symbol) (struct objfile *objfile, - int block_index, const char *name, - domain_enum domain); + contains !TYPE_OPAQUE symbol prefer its compunit. If it contains + only TYPE_OPAQUE symbol(s), return at least that compunit. */ + struct compunit_symtab *(*lookup_symbol) (struct objfile *objfile, + int block_index, const char *name, + domain_enum domain); /* Print statistics about any indices loaded for OBJFILE. The statistics should be printed to gdb_stdout. This is used for @@ -285,17 +285,15 @@ struct quick_symbol_functions enum search_domain kind, void *data); - /* Return the symbol table from OBJFILE that contains PC and - SECTION. Return NULL if there is no such symbol table. This - should return the symbol table that contains a symbol whose + /* Return the comp unit from OBJFILE that contains PC and + SECTION. Return NULL if there is no such compunit. This + should return the compunit that contains a symbol whose address exactly matches PC, or, if there is no exact match, the - symbol table that contains a symbol whose address is closest to + compunit that contains a symbol whose address is closest to PC. */ - struct symtab *(*find_pc_sect_symtab) (struct objfile *objfile, - struct bound_minimal_symbol msymbol, - CORE_ADDR pc, - struct obj_section *section, - int warn_if_readin); + struct compunit_symtab *(*find_pc_sect_compunit_symtab) + (struct objfile *objfile, struct bound_minimal_symbol msymbol, + CORE_ADDR pc, struct obj_section *section, int warn_if_readin); /* Call a callback for every file defined in OBJFILE whose symtab is not already read in. FUN is the callback. It is passed the file's @@ -418,9 +416,15 @@ extern struct symfile_segment_data *default_symfile_segments (bfd *abfd); extern bfd_byte *default_symfile_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf); -extern struct symtab *allocate_symtab (const char *, struct objfile *) +extern struct symtab *allocate_symtab (struct compunit_symtab *, const char *) ATTRIBUTE_NONNULL (1); +extern struct compunit_symtab *allocate_compunit_symtab (struct objfile *, + const char *) + ATTRIBUTE_NONNULL (1); + +extern void add_compunit_symtab_to_objfile (struct compunit_symtab *cu); + extern void add_symtab_fns (enum bfd_flavour flavour, const struct sym_fns *); /* This enum encodes bit-flags passed as ADD_FLAGS parameter to