]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/dwarf2/abbrev-cache.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / abbrev-cache.c
1 /* DWARF 2 abbrev table cache
2
3 Copyright (C) 2022-2024 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "dwarf2/read.h"
22 #include "dwarf2/abbrev-cache.h"
23
24 /* Hash function for an abbrev table. */
25
26 hashval_t
27 abbrev_cache::hash_table (const void *item)
28 {
29 const struct abbrev_table *table = (const struct abbrev_table *) item;
30 return to_underlying (table->sect_off);
31 }
32
33 /* Comparison function for abbrev table. */
34
35 int
36 abbrev_cache::eq_table (const void *lhs, const void *rhs)
37 {
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);
42 }
43
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))
48 {
49 }
50
51 void
52 abbrev_cache::add (abbrev_table_up table)
53 {
54 /* We allow this as a convenience to the caller. */
55 if (table == nullptr)
56 return;
57
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 ();
65 }