gdb/mi: add new --group-by-objfile flag for -file-list-exec-source-files
[deliverable/binutils-gdb.git] / gdb / psymtab.h
1 /* Public partial symbol table definitions.
2
3 Copyright (C) 2009-2021 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 PSYMTAB_H
21 #define PSYMTAB_H
22
23 #include "gdb_obstack.h"
24 #include "symfile.h"
25 #include "gdbsupport/next-iterator.h"
26 #include "bcache.h"
27
28 struct partial_symbol;
29
30 /* Specialization of bcache to store partial symbols. */
31
32 struct psymbol_bcache : public gdb::bcache
33 {
34 /* Calculate a hash code for the given partial symbol. The hash is
35 calculated using the symbol's value, language, domain, class
36 and name. These are the values which are set by
37 add_psymbol_to_bcache. */
38 unsigned long hash (const void *addr, int length) override;
39
40 /* Returns true if the symbol LEFT equals the symbol RIGHT.
41 For the comparison this function uses a symbols value,
42 language, domain, class and name. */
43 int compare (const void *left, const void *right, int length) override;
44 };
45
46 /* An instance of this class manages the partial symbol tables and
47 partial symbols for a given objfile.
48
49 The core psymtab functions -- those in psymtab.c -- arrange for
50 nearly all psymtab- and psymbol-related allocations to happen
51 either in the psymtab_storage object (either on its obstack or in
52 other memory managed by this class), or on the per-BFD object. The
53 only link from the psymtab storage object back to the objfile (or
54 objfile_obstack) that is made by the core psymtab code is the
55 compunit_symtab member in the standard_psymtab -- and a given
56 symbol reader can avoid this by implementing its own subclasses of
57 partial_symtab.
58
59 However, it is up to each symbol reader to maintain this invariant
60 in other ways, if it wants to reuse psymtabs across multiple
61 objfiles. The main issue here is ensuring that read_symtab_private
62 does not point into objfile_obstack. */
63
64 class psymtab_storage
65 {
66 public:
67 psymtab_storage () = default;
68 ~psymtab_storage ();
69
70 DISABLE_COPY_AND_ASSIGN (psymtab_storage);
71
72 /* Discard all partial symbol tables starting with "psymtabs" and
73 proceeding until "to" has been discarded. */
74
75 void discard_psymtabs_to (struct partial_symtab *to)
76 {
77 while (psymtabs != to)
78 discard_psymtab (psymtabs);
79 }
80
81 /* Discard the partial symbol table. */
82
83 void discard_psymtab (struct partial_symtab *pst);
84
85 /* Return the obstack that is used for storage by this object. */
86
87 struct obstack *obstack ()
88 {
89 if (!m_obstack.has_value ())
90 m_obstack.emplace ();
91 return &*m_obstack;
92 }
93
94 /* Allocate storage for the "dependencies" field of a psymtab.
95 NUMBER says how many dependencies there are. */
96
97 struct partial_symtab **allocate_dependencies (int number)
98 {
99 return OBSTACK_CALLOC (obstack (), number, struct partial_symtab *);
100 }
101
102 /* Install a psymtab on the psymtab list. This transfers ownership
103 of PST to this object. */
104
105 void install_psymtab (partial_symtab *pst);
106
107 typedef next_adapter<struct partial_symtab> partial_symtab_range;
108
109 /* A range adapter that makes it possible to iterate over all
110 psymtabs in one objfile. */
111
112 partial_symtab_range range ()
113 {
114 return partial_symtab_range (psymtabs);
115 }
116
117
118 /* Each objfile points to a linked list of partial symtabs derived from
119 this file, one partial symtab structure for each compilation unit
120 (source file). */
121
122 struct partial_symtab *psymtabs = nullptr;
123
124 /* Map addresses to the entries of PSYMTABS. It would be more efficient to
125 have a map per the whole process but ADDRMAP cannot selectively remove
126 its items during FREE_OBJFILE. This mapping is already present even for
127 PARTIAL_SYMTABs which still have no corresponding full SYMTABs read.
128
129 The DWARF parser reuses this addrmap to store things other than
130 psymtabs in the cases where debug information is being read from, for
131 example, the .debug-names section. */
132
133 struct addrmap *psymtabs_addrmap = nullptr;
134
135 /* A byte cache where we can stash arbitrary "chunks" of bytes that
136 will not change. */
137
138 psymbol_bcache psymbol_cache;
139
140 private:
141
142 /* The obstack where allocations are made. This is lazily allocated
143 so that we don't waste memory when there are no psymtabs. */
144
145 gdb::optional<auto_obstack> m_obstack;
146 };
147
148 #endif /* PSYMTAB_H */
This page took 0.031429 seconds and 4 git commands to generate.