1 /* DWARF abbrev table cache
3 Copyright (C) 2022-2024 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 #ifndef GDB_DWARF2_ABBREV_TABLE_CACHE_H
21 #define GDB_DWARF2_ABBREV_TABLE_CACHE_H
23 #include "dwarf2/abbrev.h"
24 #include "gdbsupport/unordered_set.h"
26 /* An abbrev table cache holds abbrev tables for easier reuse. */
27 class abbrev_table_cache
30 abbrev_table_cache () = default;
31 DISABLE_COPY_AND_ASSIGN (abbrev_table_cache
);
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
36 const abbrev_table
*find (dwarf2_section_info
*section
,
37 sect_offset offset
) const
39 abbrev_table_search_key key
{section
, offset
};
41 if (auto iter
= m_tables
.find (key
);
42 iter
!= m_tables
.end ())
48 /* Add TABLE to this cache. Ownership of TABLE is transferred to
49 the cache. Note that a table at a given section+offset may only
50 be registered once -- a violation of this will cause an assert.
51 To avoid this, call the 'find' method first, to see if the table
52 has already been read. */
53 void add (abbrev_table_up table
);
56 /* Key used to search for an existing abbrev table in M_TABLES. */
57 struct abbrev_table_search_key
59 const dwarf2_section_info
*section
;
63 struct abbrev_table_hash
65 using is_transparent
= void;
67 std::size_t operator() (const abbrev_table_search_key
&key
) const noexcept
69 return (std::hash
<const dwarf2_section_info
*> () (key
.section
)
70 + (std::hash
<std::underlying_type_t
<decltype (key
.sect_off
)>> ()
71 (to_underlying (key
.sect_off
))));
74 std::size_t operator() (const abbrev_table_up
&table
) const noexcept
75 { return (*this) ({ table
->section
, table
->sect_off
}); }
78 struct abbrev_table_eq
80 using is_transparent
= void;
82 bool operator() (const abbrev_table_search_key
&key
,
83 const abbrev_table_up
&table
) const noexcept
84 { return key
.section
== table
->section
&& key
.sect_off
== table
->sect_off
; }
86 bool operator() (const abbrev_table_up
&lhs
,
87 const abbrev_table_up
&rhs
) const noexcept
88 { return (*this) ({ lhs
->section
, lhs
->sect_off
}, rhs
); }
91 /* Hash table of abbrev tables. */
92 gdb::unordered_set
<abbrev_table_up
, abbrev_table_hash
, abbrev_table_eq
> m_tables
;
95 #endif /* GDB_DWARF2_ABBREV_TABLE_CACHE_H */