From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 21/38] Use htab_up in abbrev_table
Date: Thu, 23 Jan 2020 00:57:00 -0000 [thread overview]
Message-ID: <20200123005710.7978-22-tom@tromey.com> (raw)
In-Reply-To: <20200123005710.7978-1-tom@tromey.com>
This changes abbrev_table to use an htab_up rather than an ad hoc,
bucket-based hash table.
2020-01-22 Tom Tromey <tom@tromey.com>
* dwarf2/abbrev.c (abbrev_table): Move constructor from header.
Rewrite.
(abbrev_table::add_abbrev, abbrev_table::lookup_abbrev): Rewrite.
* dwarf2/abbrev.h (struct abbrev_info) <next>: Remove.
(abbrev_table::abbrev_table): No longer inline.
(ABBREV_HASH_SIZE): Remove.
(abbrev_table::m_abbrevs): Now an htab_up.
Change-Id: Icbaa8e49501f9c43218d6a81a7e8c4d3a77d65dc
---
gdb/ChangeLog | 10 ++++++++++
gdb/dwarf2/abbrev.c | 48 +++++++++++++++++++++++++++++----------------
gdb/dwarf2/abbrev.h | 19 +++---------------
3 files changed, 44 insertions(+), 33 deletions(-)
diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index fac7309b93c..f843e32d950 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -30,6 +30,25 @@
#include "dwarf2/leb.h"
#include "bfd.h"
+/* Hash function for an abbrev. */
+
+static hashval_t
+hash_abbrev (const void *item)
+{
+ const struct abbrev_info *info = (const struct abbrev_info *) item;
+ return info->number;
+}
+
+/* Comparison function for abbrevs. */
+
+static int
+eq_abbrev (const void *lhs, const void *rhs)
+{
+ const struct abbrev_info *l_info = (const struct abbrev_info *) lhs;
+ const struct abbrev_info *r_info = (const struct abbrev_info *) rhs;
+ return l_info->number == r_info->number;
+}
+
/* Abbreviation tables.
In DWARF version 2, the description of the debugging information is
@@ -37,6 +56,13 @@
dies from a section we read in all abbreviations and install them
in a hash table. */
+abbrev_table::abbrev_table (sect_offset off)
+ : sect_off (off),
+ m_abbrevs (htab_create_alloc (20, hash_abbrev, eq_abbrev,
+ nullptr, xcalloc, xfree))
+{
+}
+
/* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
struct abbrev_info *
@@ -56,11 +82,8 @@ void
abbrev_table::add_abbrev (unsigned int abbrev_number,
struct abbrev_info *abbrev)
{
- unsigned int hash_number;
-
- hash_number = abbrev_number % ABBREV_HASH_SIZE;
- abbrev->next = m_abbrevs[hash_number];
- m_abbrevs[hash_number] = abbrev;
+ void **slot = htab_find_slot (m_abbrevs.get (), abbrev, INSERT);
+ *slot = abbrev;
}
/* Look up an abbrev in the table.
@@ -69,19 +92,10 @@ abbrev_table::add_abbrev (unsigned int abbrev_number,
struct abbrev_info *
abbrev_table::lookup_abbrev (unsigned int abbrev_number)
{
- unsigned int hash_number;
- struct abbrev_info *abbrev;
-
- hash_number = abbrev_number % ABBREV_HASH_SIZE;
- abbrev = m_abbrevs[hash_number];
+ struct abbrev_info search;
+ search.number = abbrev_number;
- while (abbrev)
- {
- if (abbrev->number == abbrev_number)
- return abbrev;
- abbrev = abbrev->next;
- }
- return NULL;
+ return (struct abbrev_info *) htab_find (m_abbrevs.get (), &search);
}
/* Read in an abbrev table. */
diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h
index 52103b0a683..b9ace64b448 100644
--- a/gdb/dwarf2/abbrev.h
+++ b/gdb/dwarf2/abbrev.h
@@ -35,7 +35,6 @@ struct abbrev_info
unsigned short has_children; /* boolean */
unsigned short num_attrs; /* number of attributes */
struct attr_abbrev *attrs; /* an array of attribute descriptions */
- struct abbrev_info *next; /* next in chain */
};
struct attr_abbrev
@@ -47,9 +46,6 @@ struct attr_abbrev
LONGEST implicit_const;
};
-/* Size of abbrev_table.abbrev_hash_table. */
-#define ABBREV_HASH_SIZE 121
-
struct abbrev_table;
typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
@@ -73,13 +69,7 @@ struct abbrev_table
private:
- explicit abbrev_table (sect_offset off)
- : sect_off (off)
- {
- m_abbrevs =
- XOBNEWVEC (&m_abbrev_obstack, struct abbrev_info *, ABBREV_HASH_SIZE);
- memset (m_abbrevs, 0, ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
- }
+ explicit abbrev_table (sect_offset off);
DISABLE_COPY_AND_ASSIGN (abbrev_table);
@@ -90,11 +80,8 @@ private:
/* Add an abbreviation to the table. */
void add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev);
- /* Hash table of abbrevs.
- This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
- It could be statically allocated, but the previous code didn't so we
- don't either. */
- struct abbrev_info **m_abbrevs;
+ /* Hash table of abbrevs. */
+ htab_up m_abbrevs;
/* Storage for the abbrev table. */
auto_obstack m_abbrev_obstack;
--
2.17.2
next prev parent reply other threads:[~2020-01-23 0:57 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-23 0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
2020-01-23 0:57 ` [PATCH 12/38] Introduce die_info::has_children Tom Tromey
2020-01-23 0:57 ` [PATCH 04/38] Create dwarf2/abbrev.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 28/38] Move dwarf2_per_cu_data::imported_symtabs earlier Tom Tromey
2020-01-23 0:57 ` [PATCH 10/38] Remove die_reader_specs::comp_dir Tom Tromey
2020-01-23 0:57 ` [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up Tom Tromey
2020-02-08 16:55 ` Simon Marchi
2020-01-23 0:57 ` [PATCH 25/38] Change file_full_name and file_file_name methods Tom Tromey
2020-01-27 13:31 ` Christian Biesinger via gdb-patches
2020-01-23 0:57 ` [PATCH 18/38] Change dwp_file to use htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 24/38] Move dwarf_always_disassemble to dwarf2/loc.c Tom Tromey
2020-01-23 0:57 ` [PATCH 17/38] Don't allocate DWO file hash on obstack Tom Tromey
2020-01-23 0:57 ` [PATCH 09/38] Don't declare die_info in dwarf2read.h Tom Tromey
2020-01-23 0:57 ` [PATCH 30/38] Unify read_initial_length implementations Tom Tromey
2020-01-27 13:31 ` Christian Biesinger via gdb-patches
2020-01-28 0:54 ` Tom Tromey
2020-01-23 0:57 ` [PATCH 20/38] Minor cleanups in abbrev_table Tom Tromey
2020-01-23 0:57 ` [PATCH 38/38] Remove "keep" parameter from cutu_reader constructor Tom Tromey
2020-02-08 17:36 ` Simon Marchi
2020-01-23 0:57 ` [PATCH 05/38] Create dwarf2/attribute.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 27/38] Move DWARF line_header to new file Tom Tromey
2020-01-23 0:57 ` [PATCH 13/38] Remove DWARF queue-related globals Tom Tromey
2020-01-23 0:57 ` [PATCH 22/38] Minor simplification in abbrev_table::read Tom Tromey
2020-01-23 0:57 ` [PATCH 32/38] Move read_offset_1 to leb.c Tom Tromey
2020-01-23 0:57 ` [PATCH 16/38] Change dwarf2_per_objfile::line_header_hash to htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 07/38] Change attr_form_is_block to be a method Tom Tromey
2020-01-23 0:57 ` [PATCH 35/38] Convert read_address to a method on comp_unit_head Tom Tromey
2020-01-23 0:57 ` [PATCH 19/38] Change dwarf2_per_objfile::die_type_hash to htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 31/38] Convert dwarf2_section_size to a method Tom Tromey
2020-01-23 0:57 ` [PATCH 01/38] Create dwarf2/leb.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 08/38] Remove die_info_ptr typedef Tom Tromey
2020-01-23 0:57 ` [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory Tom Tromey
2020-01-27 13:41 ` Christian Biesinger via gdb-patches
2020-01-28 3:12 ` Tom Tromey
2020-01-23 0:57 ` [PATCH 06/38] Change some attribute functions to be methods Tom Tromey
2020-01-23 0:57 ` [PATCH 26/38] Change line_table methods to return unique_xmalloc_ptr Tom Tromey
2020-01-23 0:57 ` [PATCH 15/38] Change dwarf2_per_objfile::type_unit_groups to htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 36/38] Move two more functions to dwarf2/leb.h Tom Tromey
2020-01-23 0:57 ` [PATCH 34/38] Convert read_offset to method on comp_unit_head Tom Tromey
2020-01-23 0:57 ` Tom Tromey [this message]
2020-01-23 0:57 ` [PATCH 02/38] Create dwarf2/section.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 33/38] Create dwarf2/comp-unit.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 23/38] Change dwarf2_per_objfile::quick_file_names_table to htab_up Tom Tromey
2020-01-23 1:12 ` [PATCH 03/38] Change section functions to be methods of dwarf2_section_info Tom Tromey
2020-01-23 1:21 ` [PATCH 29/38] Add some methods to dwarf2_per_cu_data Tom Tromey
2020-01-23 2:34 ` [PATCH 37/38] Simplify "want_partial_unit" handling Tom Tromey
2020-02-08 17:38 ` [PATCH 00/38] Start reorganization of DWARF code Simon Marchi
2020-02-08 20:45 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200123005710.7978-22-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).