From patchwork Wed Jul 10 15:39:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33661 Received: (qmail 88347 invoked by alias); 10 Jul 2019 15:49:11 -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 88334 invoked by uid 89); 10 Jul 2019 15:49:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=earliest, longest, Fill X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 10 Jul 2019 15:49:09 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 4B176561DB; Wed, 10 Jul 2019 11:39:53 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id qT7T9vg+EU9V; Wed, 10 Jul 2019 11:39:53 -0400 (EDT) Received: from murgatroyd.Home (97-122-178-82.hlrn.qwest.net [97.122.178.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id E861F56128; Wed, 10 Jul 2019 11:39:52 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 9/9] Change arm-tdep.c to use type-safe registry Date: Wed, 10 Jul 2019 09:39:47 -0600 Message-Id: <20190710153947.25721-10-tromey@adacore.com> In-Reply-To: <20190710153947.25721-1-tromey@adacore.com> References: <20190710153947.25721-1-tromey@adacore.com> MIME-Version: 1.0 This changes arm-tdep.c to use the type-safe registry, removing a use of VEC in the process. gdb/ChangeLog 2019-07-10 Tom Tromey * arm-tdep.c (arm_exidx_entry_s): Remove typedef. Don't define VEC. (struct arm_exidx_entry): New method operator<. (struct arm_exidx_data) : Change type. (arm_exidx_data_free): Remove. (arm_exidx_data_key): Change type. Move lower. (arm_exidx_new_objfile): Update. (arm_compare_exidx_entries): Remove. (arm_find_exidx_entry, _initialize_arm_tdep) --- gdb/ChangeLog | 12 ++++++++ gdb/arm-tdep.c | 78 +++++++++++++++++--------------------------------- 2 files changed, 38 insertions(+), 52 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index fe6251924f9..c1ee39714f9 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -1989,37 +1989,23 @@ struct frame_unwind arm_prologue_unwind = { personality routines; the cache will contain only the frame unwinding instructions associated with the entry (not the descriptors). */ -static const struct objfile_data *arm_exidx_data_key; - struct arm_exidx_entry { bfd_vma addr; gdb_byte *entry; + + bool operator< (const arm_exidx_entry &other) const + { + return addr < other.addr; + } }; -typedef struct arm_exidx_entry arm_exidx_entry_s; -DEF_VEC_O(arm_exidx_entry_s); struct arm_exidx_data { - VEC(arm_exidx_entry_s) **section_maps; + std::vector> section_maps; }; -static void -arm_exidx_data_free (struct objfile *objfile, void *arg) -{ - struct arm_exidx_data *data = (struct arm_exidx_data *) arg; - unsigned int i; - - for (i = 0; i < objfile->obfd->section_count; i++) - VEC_free (arm_exidx_entry_s, data->section_maps[i]); -} - -static inline int -arm_compare_exidx_entries (const struct arm_exidx_entry *lhs, - const struct arm_exidx_entry *rhs) -{ - return lhs->addr < rhs->addr; -} +static const struct objfile_key arm_exidx_data_key; static struct obj_section * arm_obj_section_from_vma (struct objfile *objfile, bfd_vma vma) @@ -2064,7 +2050,7 @@ arm_exidx_new_objfile (struct objfile *objfile) LONGEST i; /* If we've already touched this file, do nothing. */ - if (!objfile || objfile_data (objfile, arm_exidx_data_key) != NULL) + if (!objfile || arm_exidx_data_key.get (objfile) != NULL) return; /* Read contents of exception table and index. */ @@ -2095,11 +2081,8 @@ arm_exidx_new_objfile (struct objfile *objfile) } /* Allocate exception table data structure. */ - data = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct arm_exidx_data); - set_objfile_data (objfile, arm_exidx_data_key, data); - data->section_maps = OBSTACK_CALLOC (&objfile->objfile_obstack, - objfile->obfd->section_count, - VEC(arm_exidx_entry_s) *); + data = arm_exidx_data_key.emplace (objfile); + data->section_maps.resize (objfile->obfd->section_count); /* Fill in exception table. */ for (i = 0; i < exidx_data.size () / 8; i++) @@ -2250,9 +2233,8 @@ arm_exidx_new_objfile (struct objfile *objfile) appear in order of increasing addresses. */ new_exidx_entry.addr = idx; new_exidx_entry.entry = entry; - VEC_safe_push (arm_exidx_entry_s, - data->section_maps[sec->the_bfd_section->index], - &new_exidx_entry); + data->section_maps[sec->the_bfd_section->index].push_back + (new_exidx_entry); } } @@ -2269,43 +2251,37 @@ arm_find_exidx_entry (CORE_ADDR memaddr, CORE_ADDR *start) if (sec != NULL) { struct arm_exidx_data *data; - VEC(arm_exidx_entry_s) *map; struct arm_exidx_entry map_key = { memaddr - obj_section_addr (sec), 0 }; - unsigned int idx; - data = ((struct arm_exidx_data *) - objfile_data (sec->objfile, arm_exidx_data_key)); + data = arm_exidx_data_key.get (sec->objfile); if (data != NULL) { - map = data->section_maps[sec->the_bfd_section->index]; - if (!VEC_empty (arm_exidx_entry_s, map)) + std::vector &map + = data->section_maps[sec->the_bfd_section->index]; + if (!map.empty ()) { - struct arm_exidx_entry *map_sym; - - idx = VEC_lower_bound (arm_exidx_entry_s, map, &map_key, - arm_compare_exidx_entries); + auto idx = std::lower_bound (map.begin (), map.end (), map_key); - /* VEC_lower_bound finds the earliest ordered insertion + /* std::lower_bound finds the earliest ordered insertion point. If the following symbol starts at this exact address, we use that; otherwise, the preceding exception table entry covers this address. */ - if (idx < VEC_length (arm_exidx_entry_s, map)) + if (idx < map.end ()) { - map_sym = VEC_index (arm_exidx_entry_s, map, idx); - if (map_sym->addr == map_key.addr) + if (idx->addr == map_key.addr) { if (start) - *start = map_sym->addr + obj_section_addr (sec); - return map_sym->entry; + *start = idx->addr + obj_section_addr (sec); + return idx->entry; } } - if (idx > 0) + if (idx > map.begin ()) { - map_sym = VEC_index (arm_exidx_entry_s, map, idx - 1); + idx = idx - 1; if (start) - *start = map_sym->addr + obj_section_addr (sec); - return map_sym->entry; + *start = idx->addr + obj_section_addr (sec); + return idx->entry; } } } @@ -9461,8 +9437,6 @@ _initialize_arm_tdep (void) /* Add ourselves to objfile event chain. */ gdb::observers::new_objfile.attach (arm_exidx_new_objfile); - arm_exidx_data_key - = register_objfile_data_with_cleanup (NULL, arm_exidx_data_free); /* Register an ELF OS ABI sniffer for ARM binaries. */ gdbarch_register_osabi_sniffer (bfd_arch_arm,