From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113152 invoked by alias); 23 May 2018 04:59:02 -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 113103 invoked by uid 89); 23 May 2018 04:59:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 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.2 spammy=cust, iow, hacks, IOW X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 May 2018 04:59:00 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 90BD144767 for ; Tue, 22 May 2018 23:58:58 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id LLrWfw7Y579N3LLrWfSj19; Tue, 22 May 2018 23:58:58 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:56108 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fLLrW-003S5D-BE; Tue, 22 May 2018 23:58:58 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 01/42] Use new and delete for buildsym_compunit Date: Wed, 23 May 2018 04:59:00 -0000 Message-Id: <20180523045851.11660-2-tom@tromey.com> In-Reply-To: <20180523045851.11660-1-tom@tromey.com> References: <20180523045851.11660-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fLLrW-003S5D-BE X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:56108 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-05/txt/msg00575.txt.bz2 This changes buildsym_compunit to use new and delete. gdb/ChangeLog 2018-05-22 Tom Tromey * buildsym.c (struct buildsym_compunit): Add constructor, destructor, initializers. (start_buildsym_compunit): Remove. (free_buildsym_compunit): Use "delete". (start_symtab, restart_symtab): Use "new". --- gdb/ChangeLog | 8 ++++++ gdb/buildsym.c | 91 ++++++++++++++++++++++++++-------------------------------- 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 5d38cb250f..9863e4ea1e 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -100,6 +100,35 @@ struct buildsym_compunit { + /* Start recording information about a primary source file (IOW, not an + included source file). + COMP_DIR is the directory in which the compilation unit was compiled + (or NULL if not known). */ + + buildsym_compunit (struct objfile *objfile_, const char *comp_dir_, + enum language language_) + : objfile (objfile_), + comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)), + language (language_) + { + } + + ~buildsym_compunit () + { + struct subfile *subfile, *nextsub; + + for (subfile = subfiles; + subfile != NULL; + subfile = nextsub) + { + nextsub = subfile->next; + xfree (subfile->name); + xfree (subfile->line_vector); + xfree (subfile); + } + xfree (comp_dir); + } + /* The objfile we're reading debug info from. */ struct objfile *objfile; @@ -107,24 +136,24 @@ struct buildsym_compunit Files are added to the front of the list. This is important mostly for the language determination hacks we use, which iterate over previously added files. */ - struct subfile *subfiles; + struct subfile *subfiles = nullptr; /* The subfile of the main source file. */ - struct subfile *main_subfile; + struct subfile *main_subfile = nullptr; /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */ char *comp_dir; /* Space for this is not malloc'd, and is assumed to have at least the same lifetime as objfile. */ - const char *producer; + const char *producer = nullptr; /* Space for this is not malloc'd, and is assumed to have at least the same lifetime as objfile. */ - const char *debugformat; + const char *debugformat = nullptr; /* The compunit we are building. */ - struct compunit_symtab *compunit_symtab; + struct compunit_symtab *compunit_symtab = nullptr; /* Language of this compunit_symtab. */ enum language language; @@ -763,54 +792,14 @@ start_subfile (const char *name) } } -/* Start recording information about a primary source file (IOW, not an - included source file). - COMP_DIR is the directory in which the compilation unit was compiled - (or NULL if not known). */ - -static struct buildsym_compunit * -start_buildsym_compunit (struct objfile *objfile, const char *comp_dir, - enum language language) -{ - struct buildsym_compunit *bscu; - - bscu = XNEW (struct buildsym_compunit); - memset (bscu, 0, sizeof (struct buildsym_compunit)); - - bscu->objfile = objfile; - bscu->comp_dir = (comp_dir == NULL) ? NULL : xstrdup (comp_dir); - bscu->language = language; - - /* Initialize the debug format string to NULL. We may supply it - later via a call to record_debugformat. */ - bscu->debugformat = NULL; - - /* Similarly for the producer. */ - bscu->producer = NULL; - - return bscu; -} - /* Delete the buildsym compunit. */ static void free_buildsym_compunit (void) { - struct subfile *subfile, *nextsub; - if (buildsym_compunit == NULL) return; - for (subfile = buildsym_compunit->subfiles; - subfile != NULL; - subfile = nextsub) - { - nextsub = subfile->next; - xfree (subfile->name); - xfree (subfile->line_vector); - xfree (subfile); - } - xfree (buildsym_compunit->comp_dir); - xfree (buildsym_compunit); + delete buildsym_compunit; buildsym_compunit = NULL; current_subfile = NULL; } @@ -1057,7 +1046,8 @@ start_symtab (struct objfile *objfile, const char *name, const char *comp_dir, { prepare_for_building (name, start_addr); - buildsym_compunit = start_buildsym_compunit (objfile, comp_dir, language); + buildsym_compunit = new struct buildsym_compunit (objfile, comp_dir, + language); /* Allocate the compunit symtab now. The caller needs it to allocate non-primary symtabs. It is also needed by get_macro_table. */ @@ -1093,9 +1083,10 @@ restart_symtab (struct compunit_symtab *cust, { prepare_for_building (name, start_addr); - buildsym_compunit = start_buildsym_compunit (COMPUNIT_OBJFILE (cust), - COMPUNIT_DIRNAME (cust), - compunit_language (cust)); + buildsym_compunit + = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust), + COMPUNIT_DIRNAME (cust), + compunit_language (cust)); buildsym_compunit->compunit_symtab = cust; } -- 2.13.6