From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25692 invoked by alias); 2 Jun 2017 12:29:39 -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 25039 invoked by uid 89); 2 Jun 2017 12:29:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_STOCKGEN,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Jun 2017 12:29:30 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CAE961E51 for ; Fri, 2 Jun 2017 12:22:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7CAE961E51 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7CAE961E51 Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01FA84DA6D for ; Fri, 2 Jun 2017 12:22:45 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 07/40] objfile_per_bfd_storage non-POD Date: Fri, 02 Jun 2017 12:29:00 -0000 Message-Id: <1496406158-12663-8-git-send-email-palves@redhat.com> In-Reply-To: <1496406158-12663-1-git-send-email-palves@redhat.com> References: <1496406158-12663-1-git-send-email-palves@redhat.com> X-SW-Source: 2017-06/txt/msg00035.txt.bz2 A following patch will want to add a std::vector to objfile_per_bfd_storage. That makes it non-trivially constructible/destructible. Since objfile_per_bfd_storage objects are allocated on an obstack, we need to call their ctors/dtors manually. This is what this patch does. And then since we can now rely on ctors/dtors being run, make objfile_per_bfd_storage::storage_obstack be an auto_obstack. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * objfiles.c (get_objfile_bfd_data): Call bfd_alloc instead of bfd_zalloc. Call objfile_per_bfd_storage's ctor. (free_objfile_per_bfd_storage): Call objfile_per_bfd_storage's dtor. * objfiles.h (objfile_per_bfd_storage): Add ctor. Make 'storage_obstack' field an auto_obstack. In-class initialize all non-bitfield fields. Make minsyms_read bool. * symfile.c (read_symbols): Adjust. --- gdb/objfiles.c | 15 +++++++++++---- gdb/objfiles.h | 32 ++++++++++++++++++-------------- gdb/symfile.c | 2 +- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 9500b1c..d261c87 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -142,12 +142,19 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd) { storage = ((struct objfile_per_bfd_storage *) - bfd_zalloc (abfd, sizeof (struct objfile_per_bfd_storage))); + bfd_alloc (abfd, sizeof (struct objfile_per_bfd_storage))); set_bfd_data (abfd, objfiles_bfd_data, storage); } else - storage = OBSTACK_ZALLOC (&objfile->objfile_obstack, - struct objfile_per_bfd_storage); + { + storage = (objfile_per_bfd_storage *) + obstack_alloc (&objfile->objfile_obstack, + sizeof (objfile_per_bfd_storage)); + } + + /* objfile_per_bfd_storage is not trivially constructible, must + call the ctor manually. */ + storage = new (storage) objfile_per_bfd_storage (); /* Look up the gdbarch associated with the BFD. */ if (abfd != NULL) @@ -171,7 +178,7 @@ free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage) bcache_xfree (storage->macro_cache); if (storage->demangled_names_hash) htab_delete (storage->demangled_names_hash); - obstack_free (&storage->storage_obstack, 0); + storage->~objfile_per_bfd_storage (); } /* A wrapper for free_objfile_per_bfd_storage that can be passed as a diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 58db6c9..3260425 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -184,24 +184,28 @@ extern void print_symbol_bcache_statistics (void); struct objfile_per_bfd_storage { + objfile_per_bfd_storage () + : minsyms_read (false) + {} + /* The storage has an obstack of its own. */ - struct obstack storage_obstack; + auto_obstack storage_obstack; /* Byte cache for file names. */ - struct bcache *filename_cache; + bcache *filename_cache = NULL; /* Byte cache for macros. */ - struct bcache *macro_cache; + bcache *macro_cache = NULL; /* The gdbarch associated with the BFD. Note that this gdbarch is determined solely from BFD information, without looking at target information. The gdbarch determined from a running target may differ from this e.g. with respect to register types and names. */ - struct gdbarch *gdbarch; + struct gdbarch *gdbarch = NULL; /* Hash table for mapping symbol names to demangled names. Each entry in the hash table is actually two consecutive strings, @@ -209,19 +213,19 @@ struct objfile_per_bfd_storage name, and the second is the demangled name or just a zero byte if the name doesn't demangle. */ - struct htab *demangled_names_hash; + htab *demangled_names_hash = NULL; /* The per-objfile information about the entry point, the scope (file/func) containing the entry point, and the scope of the user's main() func. */ - struct entry_info ei; + entry_info ei {}; /* The name and language of any "main" found in this objfile. The name can be NULL, which means that the information was not recorded. */ - const char *name_of_main; - enum language language_of_main; + const char *name_of_main = NULL; + enum language language_of_main = language_unknown; /* Each file contains a pointer to an array of minimal symbols for all global symbols that are defined within the file. The array is @@ -233,15 +237,15 @@ struct objfile_per_bfd_storage as all the data that it points to, should be allocated on the objfile_obstack for this file. */ - struct minimal_symbol *msymbols; - int minimal_symbol_count; + minimal_symbol *msymbols = NULL; + int minimal_symbol_count = 0; /* The number of minimal symbols read, before any minimal symbol de-duplication is applied. Note in particular that this has only a passing relationship with the actual size of the table above; use minimal_symbol_count if you need the true size. */ - int n_minsyms; + int n_minsyms = 0; /* This is true if minimal symbols have already been read. Symbol readers can use this to bypass minimal symbol reading. Also, the @@ -251,16 +255,16 @@ struct objfile_per_bfd_storage for multiple readers to install minimal symbols into a given per-BFD. */ - unsigned int minsyms_read : 1; + bool minsyms_read : 1; /* This is a hash table used to index the minimal symbols by name. */ - struct minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE]; + minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE] {}; /* This hash table is used to index the minimal symbols by their demangled names. */ - struct minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE]; + minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE] {}; }; /* Master structure for keeping track of each file from which diff --git a/gdb/symfile.c b/gdb/symfile.c index 846aabe..7892d17 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -859,7 +859,7 @@ static void read_symbols (struct objfile *objfile, symfile_add_flags add_flags) { (*objfile->sf->sym_read) (objfile, add_flags); - objfile->per_bfd->minsyms_read = 1; + objfile->per_bfd->minsyms_read = true; /* find_separate_debug_file_in_section should be called only if there is single binary with no existing separate debug info file. */ -- 2.5.5