From patchwork Fri Dec 13 06:03:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 36827 Received: (qmail 85549 invoked by alias); 13 Dec 2019 06:03:32 -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 85511 invoked by uid 89); 13 Dec 2019 06:03:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.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_SOFTFAIL autolearn=ham version=3.3.1 spammy=7817, management, HContent-Transfer-Encoding:8bit X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Dec 2019 06:03:28 +0000 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id iSl2h90FFNbfS1Vi (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 13 Dec 2019 01:03:27 -0500 (EST) Received: from simark.lan (unknown [192.222.164.54]) by smtp.ebox.ca (Postfix) with ESMTP id 168AB441B21; Fri, 13 Dec 2019 01:03:27 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/7] jit: make gdb_object::symtabs a vector Date: Fri, 13 Dec 2019 01:03:18 -0500 Message-Id: <20191213060323.1799590-3-simon.marchi@polymtl.ca> In-Reply-To: <20191213060323.1799590-1-simon.marchi@polymtl.ca> References: <20191213060323.1799590-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-IsSubscribed: yes Replace the manual linked list with a vector, simplifying the memory management. This requires allocating gdb_object with new and freeing it with delete. gdb/ChangeLog: * jit.c (struct gdb_symtab) : Remove field. (struct gdb_object) : Change type to std::vector. (jit_object_open_impl): Allocate gdb_object with new. (jit_symtab_open_impl): Adjust to std::vector. (jit_object_close_impl): Adjust to std::vector. --- gdb/jit.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/gdb/jit.c b/gdb/jit.c index f8b12443ba8d..672a74044af3 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -462,14 +462,13 @@ struct gdb_symtab /* The source file for this symtab. */ const char *file_name; - struct gdb_symtab *next; }; /* Proxy object for building an object. */ struct gdb_object { - struct gdb_symtab *symtabs; + std::vector symtabs; }; /* The type of the `private' data passed around by the callback @@ -501,7 +500,7 @@ jit_object_open_impl (struct gdb_symbol_callbacks *cb) /* CB is not required right now, but sometime in the future we might need a handle to it, and we'd like to do that without breaking the ABI. */ - return XCNEW (struct gdb_object); + return new gdb_object; } /* Readers call into this function to open a new gdb_symtab, which, @@ -518,8 +517,7 @@ jit_symtab_open_impl (struct gdb_symbol_callbacks *cb, ret = XCNEW (struct gdb_symtab); ret->file_name = file_name ? xstrdup (file_name) : xstrdup (""); - ret->next = object->symtabs; - object->symtabs = ret; + object->symtabs.push_back (ret); return ret; } @@ -781,7 +779,6 @@ static void jit_object_close_impl (struct gdb_symbol_callbacks *cb, struct gdb_object *obj) { - struct gdb_symtab *i, *j; struct objfile *objfile; jit_dbg_reader_data *priv_data; @@ -791,14 +788,12 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb, OBJF_NOT_FILENAME); objfile->per_bfd->gdbarch = target_gdbarch (); - j = NULL; - for (i = obj->symtabs; i; i = j) - { - j = i->next; - finalize_symtab (i, objfile); - } + for (gdb_symtab *symtab : obj->symtabs) + finalize_symtab (symtab, objfile); + add_objfile_entry (objfile, *priv_data); - xfree (obj); + + delete obj; } /* Try to read CODE_ENTRY using the loaded jit reader (if any).