xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/dwarf2/abbrev-cache.h (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1*6881a400Schristos /* DWARF abbrev table cache
2*6881a400Schristos 
3*6881a400Schristos    Copyright (C) 2022-2023 Free Software Foundation, Inc.
4*6881a400Schristos 
5*6881a400Schristos    This file is part of GDB.
6*6881a400Schristos 
7*6881a400Schristos    This program is free software; you can redistribute it and/or modify
8*6881a400Schristos    it under the terms of the GNU General Public License as published by
9*6881a400Schristos    the Free Software Foundation; either version 3 of the License, or
10*6881a400Schristos    (at your option) any later version.
11*6881a400Schristos 
12*6881a400Schristos    This program is distributed in the hope that it will be useful,
13*6881a400Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*6881a400Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*6881a400Schristos    GNU General Public License for more details.
16*6881a400Schristos 
17*6881a400Schristos    You should have received a copy of the GNU General Public License
18*6881a400Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*6881a400Schristos 
20*6881a400Schristos #ifndef GDB_DWARF2_ABBREV_CACHE_H
21*6881a400Schristos #define GDB_DWARF2_ABBREV_CACHE_H
22*6881a400Schristos 
23*6881a400Schristos #include "dwarf2/abbrev.h"
24*6881a400Schristos #include "gdbtypes.h"
25*6881a400Schristos 
26*6881a400Schristos /* An abbrev cache holds abbrev tables for easier reuse.  */
27*6881a400Schristos class abbrev_cache
28*6881a400Schristos {
29*6881a400Schristos public:
30*6881a400Schristos   abbrev_cache ();
31*6881a400Schristos   DISABLE_COPY_AND_ASSIGN (abbrev_cache);
32*6881a400Schristos 
33*6881a400Schristos   /* Find an abbrev table coming from the abbrev section SECTION at
34*6881a400Schristos      offset OFFSET.  Return the table, or nullptr if it has not yet
35*6881a400Schristos      been registered.  */
36*6881a400Schristos   abbrev_table *find (struct dwarf2_section_info *section, sect_offset offset)
37*6881a400Schristos   {
38*6881a400Schristos     search_key key = { section, offset };
39*6881a400Schristos 
40*6881a400Schristos     return (abbrev_table *) htab_find_with_hash (m_tables.get (), &key,
41*6881a400Schristos 						 to_underlying (offset));
42*6881a400Schristos   }
43*6881a400Schristos 
44*6881a400Schristos   /* Add TABLE to this cache.  Ownership of TABLE is transferred to
45*6881a400Schristos      the cache.  Note that a table at a given section+offset may only
46*6881a400Schristos      be registered once -- a violation of this will cause an assert.
47*6881a400Schristos      To avoid this, call the 'find' method first, to see if the table
48*6881a400Schristos      has already been read.  */
49*6881a400Schristos   void add (abbrev_table_up table);
50*6881a400Schristos 
51*6881a400Schristos private:
52*6881a400Schristos 
53*6881a400Schristos   static hashval_t hash_table (const void *item);
54*6881a400Schristos   static int eq_table (const void *lhs, const void *rhs);
55*6881a400Schristos 
56*6881a400Schristos   struct search_key
57*6881a400Schristos   {
58*6881a400Schristos     struct dwarf2_section_info *section;
59*6881a400Schristos     sect_offset offset;
60*6881a400Schristos   };
61*6881a400Schristos 
62*6881a400Schristos   /* Hash table of abbrev tables.  */
63*6881a400Schristos   htab_up m_tables;
64*6881a400Schristos };
65*6881a400Schristos 
66*6881a400Schristos #endif /* GDB_DWARF2_ABBREV_CACHE_H */
67