Fix a new warning on Cygwin
[binutils-gdb.git] / gdb / dwarf2 / abbrev-cache.h
1 /* DWARF abbrev table cache
2
3 Copyright (C) 2022 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 #ifndef GDB_DWARF2_ABBREV_CACHE_H
21 #define GDB_DWARF2_ABBREV_CACHE_H
22
23 #include "dwarf2/abbrev.h"
24 #include "gdbtypes.h"
25
26 /* An abbrev cache holds abbrev tables for easier reuse. */
27 class abbrev_cache
28 {
29 public:
30 abbrev_cache ();
31 DISABLE_COPY_AND_ASSIGN (abbrev_cache);
32
33 /* Find an abbrev table coming from the abbrev section SECTION at
34 offset OFFSET. Return the table, or nullptr if it has not yet
35 been registered. */
36 abbrev_table *find (struct dwarf2_section_info *section, sect_offset offset)
37 {
38 search_key key = { section, offset };
39
40 return (abbrev_table *) htab_find_with_hash (m_tables.get (), &key,
41 to_underlying (offset));
42 }
43
44 /* Add TABLE to this cache. Ownership of TABLE is transferred to
45 the cache. Note that a table at a given section+offset may only
46 be registered once -- a violation of this will cause an assert.
47 To avoid this, call the 'find' method first, to see if the table
48 has already been read. */
49 void add (abbrev_table_up table);
50
51 private:
52
53 static hashval_t hash_table (const void *item);
54 static int eq_table (const void *lhs, const void *rhs);
55
56 struct search_key
57 {
58 struct dwarf2_section_info *section;
59 sect_offset offset;
60 };
61
62 /* Hash table of abbrev tables. */
63 htab_up m_tables;
64 };
65
66 #endif /* GDB_DWARF2_ABBREV_CACHE_H */