gdb/testsuite: fix gdb.trace/signal.exp on x86
[binutils-gdb/blckswan.git] / gdb / dwarf2 / abbrev-cache.c
blob2168f92dd9d9678cc68237ca93d78f97bd21b1d7
1 /* DWARF 2 abbrev table cache
3 Copyright (C) 2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "dwarf2/read.h"
22 #include "dwarf2/abbrev-cache.h"
24 /* Hash function for an abbrev table. */
26 hashval_t
27 abbrev_cache::hash_table (const void *item)
29 const struct abbrev_table *table = (const struct abbrev_table *) item;
30 return to_underlying (table->sect_off);
33 /* Comparison function for abbrev table. */
35 int
36 abbrev_cache::eq_table (const void *lhs, const void *rhs)
38 const struct abbrev_table *l_table = (const struct abbrev_table *) lhs;
39 const search_key *key = (const search_key *) rhs;
40 return (l_table->section == key->section
41 && l_table->sect_off == key->offset);
44 abbrev_cache::abbrev_cache ()
45 : m_tables (htab_create_alloc (20, hash_table, eq_table,
46 htab_delete_entry<abbrev_table>,
47 xcalloc, xfree))
51 void
52 abbrev_cache::add (abbrev_table_up table)
54 /* We allow this as a convenience to the caller. */
55 if (table == nullptr)
56 return;
58 search_key key = { table->section, table->sect_off };
59 void **slot = htab_find_slot_with_hash (m_tables.get (), &key,
60 to_underlying (table->sect_off),
61 INSERT);
62 /* If this one already existed, then it should have been reused. */
63 gdb_assert (*slot == nullptr);
64 *slot = (void *) table.release ();