From patchwork Fri May 3 23:12:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32529 Received: (qmail 1300 invoked by alias); 3 May 2019 23:12:50 -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 408 invoked by uid 89); 3 May 2019 23:12:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=user-visible, uservisible, stab X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.54.2) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:40 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway20.websitewelcome.com (Postfix) with ESMTP id CD012400C4A46 for ; Fri, 3 May 2019 18:12:38 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM6hLRl52qH7MhM6he37Q; Fri, 03 May 2019 18:12:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=uUkeaIweYOETXsips3q+OJbcjBeilqIGboj+vAd/8ZE=; b=cWON8tOrGuBodCstCgPs00v6Ji y5UDOytGAkATz046O06GD+4TLTgJTA7OlgfXouNz/6KeXl6fRp6uzocxRkypWtC/zEWs98Wmh9nII QWKGxCUOFgJ03DGRgoDa50qMw; Received: from 97-122-168-123.hlrn.qwest.net ([97.122.168.123]:37502 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hMhM6-003AAO-KN; Fri, 03 May 2019 18:12:38 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 20/31] Convert coffread.c to type-safe registry API Date: Fri, 3 May 2019 17:12:20 -0600 Message-Id: <20190503231231.8954-21-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes coffread.c to use the type-safe registry API. 2019-05-01 Tom Tromey * coffread.c (struct coff_symfile_info): Add initializers. (coff_objfile_data_key): Move lower. Change type. (coff_symfile_init, coff_symfile_read, _initialize_coffread): Update. (coff_free_info): Remove. --- gdb/ChangeLog | 8 ++++++++ gdb/coffread.c | 38 ++++++++++++-------------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index 4354741ab64..0956f3897b4 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -43,26 +43,26 @@ #include "psymtab.h" #include "build-id.h" -/* Key for COFF-associated data. */ - -static const struct objfile_data *coff_objfile_data_key; - /* The objfile we are currently reading. */ static struct objfile *coffread_objfile; struct coff_symfile_info { - file_ptr min_lineno_offset; /* Where in file lowest line#s are. */ - file_ptr max_lineno_offset; /* 1+last byte of line#s in file. */ + file_ptr min_lineno_offset = 0; /* Where in file lowest line#s are. */ + file_ptr max_lineno_offset = 0; /* 1+last byte of line#s in file. */ - CORE_ADDR textaddr; /* Addr of .text section. */ - unsigned int textsize; /* Size of .text section. */ + CORE_ADDR textaddr = 0; /* Addr of .text section. */ + unsigned int textsize = 0; /* Size of .text section. */ std::vector *stabsects; /* .stab sections. */ - asection *stabstrsect; /* Section pointer for .stab section. */ - char *stabstrdata; + asection *stabstrsect = nullptr; /* Section pointer for .stab section. */ + char *stabstrdata = nullptr; }; +/* Key for COFF-associated data. */ + +static const struct objfile_key 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) \ @@ -485,15 +485,13 @@ static void coff_symfile_init (struct objfile *objfile) { struct dbx_symfile_info *dbx; - struct coff_symfile_info *coff; /* Allocate struct to keep track of stab reading. */ dbx = XCNEW (struct dbx_symfile_info); set_objfile_data (objfile, dbx_objfile_data_key, dbx); /* Allocate struct to keep track of the symfile. */ - coff = XCNEW (struct coff_symfile_info); - set_objfile_data (objfile, coff_objfile_data_key, coff); + coff_objfile_data_key.emplace (objfile); /* COFF objects may be reordered, so set OBJF_REORDERED. If we find this causes a significant slowdown in gdb then we could @@ -554,8 +552,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) int stringtab_offset; int stabstrsize; - info = (struct coff_symfile_info *) objfile_data (objfile, - coff_objfile_data_key); + info = coff_objfile_data_key.get (objfile); symfile_bfd = abfd; /* Kludge for swap routines. */ std::vector stabsects; @@ -2211,22 +2208,11 @@ static const struct sym_fns coff_sym_fns = &psym_functions }; -/* Free the per-objfile COFF data. */ - -static void -coff_free_info (struct objfile *objfile, void *arg) -{ - xfree (arg); -} - void _initialize_coffread (void) { add_symtab_fns (bfd_target_coff_flavour, &coff_sym_fns); - coff_objfile_data_key = register_objfile_data_with_cleanup (NULL, - coff_free_info); - coff_register_index = register_symbol_register_impl (LOC_REGISTER, &coff_register_funcs); }