Add block_search_flags
[binutils-gdb.git] / gdb / quick-symbol.h
1 /* "Quick" symbol functions
2
3 Copyright (C) 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 GDB_QUICK_SYMBOL_H
21 #define GDB_QUICK_SYMBOL_H
22
23 /* Like block_enum, but used as flags to pass to lookup functions. */
24
25 enum block_search_flag_values
26 {
27 SEARCH_GLOBAL_BLOCK = 1,
28 SEARCH_STATIC_BLOCK = 2
29 };
30
31 DEF_ENUM_FLAGS_TYPE (enum block_search_flag_values, block_search_flags);
32
33 /* Comparison function for symbol look ups. */
34
35 typedef int (symbol_compare_ftype) (const char *string1,
36 const char *string2);
37
38 /* Callback for quick_symbol_functions->map_symbol_filenames. */
39
40 typedef void (symbol_filename_ftype) (const char *filename,
41 const char *fullname);
42
43 /* Callback for quick_symbol_functions->expand_symtabs_matching
44 to match a file name. */
45
46 typedef bool (expand_symtabs_file_matcher_ftype) (const char *filename,
47 bool basenames);
48
49 /* Callback for quick_symbol_functions->expand_symtabs_matching
50 to match a symbol name. */
51
52 typedef bool (expand_symtabs_symbol_matcher_ftype) (const char *name);
53
54 /* Callback for quick_symbol_functions->expand_symtabs_matching
55 to be called after a symtab has been expanded. */
56
57 typedef void (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
58
59 /* The "quick" symbol functions exist so that symbol readers can
60 avoiding an initial read of all the symbols. For example, symbol
61 readers might choose to use the "partial symbol table" utilities,
62 which is one implementation of the quick symbol functions.
63
64 The quick symbol functions are generally opaque: the underlying
65 representation is hidden from the caller.
66
67 In general, these functions should only look at whatever special
68 index the symbol reader creates -- looking through the symbol
69 tables themselves is handled by generic code. If a function is
70 defined as returning a "symbol table", this means that the function
71 should only return a newly-created symbol table; it should not
72 examine pre-existing ones.
73
74 The exact list of functions here was determined in an ad hoc way
75 based on gdb's history. */
76
77 struct quick_symbol_functions
78 {
79 virtual ~quick_symbol_functions ()
80 {
81 }
82
83 /* Return true if this objfile has any "partial" symbols
84 available. */
85 virtual bool has_symbols (struct objfile *objfile) = 0;
86
87 /* Return the symbol table for the "last" file appearing in
88 OBJFILE. */
89 virtual struct symtab *find_last_source_symtab (struct objfile *objfile) = 0;
90
91 /* Forget all cached full file names for OBJFILE. */
92 virtual void forget_cached_source_info (struct objfile *objfile) = 0;
93
94 /* Expand and iterate over each "partial" symbol table in OBJFILE
95 where the source file is named NAME.
96
97 If NAME is not absolute, a match after a '/' in the symbol table's
98 file name will also work, REAL_PATH is NULL then. If NAME is
99 absolute then REAL_PATH is non-NULL absolute file name as resolved
100 via gdb_realpath from NAME.
101
102 If a match is found, the "partial" symbol table is expanded.
103 Then, this calls iterate_over_some_symtabs (or equivalent) over
104 all newly-created symbol tables, passing CALLBACK to it.
105 The result of this call is returned. */
106 virtual bool map_symtabs_matching_filename
107 (struct objfile *objfile, const char *name, const char *real_path,
108 gdb::function_view<bool (symtab *)> callback) = 0;
109
110 /* Check to see if the symbol is defined in a "partial" symbol table
111 of OBJFILE. BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
112 depending on whether we want to search global symbols or static
113 symbols. NAME is the name of the symbol to look for. DOMAIN
114 indicates what sort of symbol to search for.
115
116 Returns the newly-expanded compunit in which the symbol is
117 defined, or NULL if no such symbol table exists. If OBJFILE
118 contains !TYPE_OPAQUE symbol prefer its compunit. If it contains
119 only TYPE_OPAQUE symbol(s), return at least that compunit. */
120 virtual struct compunit_symtab *lookup_symbol (struct objfile *objfile,
121 block_enum block_index,
122 const char *name,
123 domain_enum domain) = 0;
124
125 /* Check to see if the global symbol is defined in a "partial" symbol table
126 of OBJFILE. NAME is the name of the symbol to look for. DOMAIN
127 indicates what sort of symbol to search for.
128
129 If found, sets *symbol_found_p to true and returns the symbol language.
130 defined, or NULL if no such symbol table exists. */
131 virtual enum language lookup_global_symbol_language
132 (struct objfile *objfile,
133 const char *name,
134 domain_enum domain,
135 bool *symbol_found_p) = 0;
136
137 /* Print statistics about any indices loaded for OBJFILE. The
138 statistics should be printed to gdb_stdout. This is used for
139 "maint print statistics". Statistics are printed in two
140 sections. PRINT_BCACHE is false when printing the first section
141 of general statistics, and true when printing bcache statistics. */
142 virtual void print_stats (struct objfile *objfile, bool print_bcache) = 0;
143
144 /* Dump any indices loaded for OBJFILE. The dump should go to
145 gdb_stdout. This is used for "maint print objfiles". */
146 virtual void dump (struct objfile *objfile) = 0;
147
148 /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
149 the corresponding symbol tables are loaded. */
150 virtual void expand_symtabs_for_function (struct objfile *objfile,
151 const char *func_name) = 0;
152
153 /* Read all symbol tables associated with OBJFILE. */
154 virtual void expand_all_symtabs (struct objfile *objfile) = 0;
155
156 /* Read all symbol tables associated with OBJFILE which have
157 symtab_to_fullname equal to FULLNAME.
158 This is for the purposes of examining code only, e.g., expand_line_sal.
159 The routine may ignore debug info that is known to not be useful with
160 code, e.g., DW_TAG_type_unit for dwarf debug info. */
161 virtual void expand_symtabs_with_fullname (struct objfile *objfile,
162 const char *fullname) = 0;
163
164 /* Find global or static symbols in all tables that are in DOMAIN
165 and for which MATCH (symbol name, NAME) == 0, passing each to
166 CALLBACK, reading in partial symbol tables as needed. Look
167 through global symbols if GLOBAL and otherwise static symbols.
168 Passes NAME and NAMESPACE to CALLBACK with each symbol
169 found. After each block is processed, passes NULL to CALLBACK.
170 MATCH must be weaker than strcmp_iw_ordered in the sense that
171 strcmp_iw_ordered(x,y) == 0 --> MATCH(x,y) == 0. ORDERED_COMPARE,
172 if non-null, must be an ordering relation compatible with
173 strcmp_iw_ordered in the sense that
174 strcmp_iw_ordered(x,y) == 0 --> ORDERED_COMPARE(x,y) == 0
175 and
176 strcmp_iw_ordered(x,y) <= 0 --> ORDERED_COMPARE(x,y) <= 0
177 (allowing strcmp_iw_ordered(x,y) < 0 while ORDERED_COMPARE(x, y) == 0).
178 CALLBACK returns true to indicate that the scan should continue, or
179 false to indicate that the scan should be terminated. */
180
181 virtual void map_matching_symbols
182 (struct objfile *,
183 const lookup_name_info &lookup_name,
184 domain_enum domain,
185 int global,
186 gdb::function_view<symbol_found_callback_ftype> callback,
187 symbol_compare_ftype *ordered_compare) = 0;
188
189 /* Expand all symbol tables in OBJFILE matching some criteria.
190
191 FILE_MATCHER is called for each file in OBJFILE. The file name
192 is passed to it. If the matcher returns false, the file is
193 skipped. If FILE_MATCHER is NULL the file is not skipped. If
194 BASENAMES is true the matcher should consider only file base
195 names (the passed file name is already only the lbasename'd
196 part).
197
198 If the file is not skipped, and SYMBOL_MATCHER and LOOKUP_NAME are NULL,
199 the symbol table is expanded.
200
201 Otherwise, individual symbols are considered.
202
203 If KIND does not match, the symbol is skipped.
204
205 If the symbol name does not match LOOKUP_NAME, the symbol is skipped.
206
207 If SYMBOL_MATCHER returns false, then the symbol is skipped.
208
209 Otherwise, the symbol's symbol table is expanded. */
210 virtual void expand_symtabs_matching
211 (struct objfile *objfile,
212 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
213 const lookup_name_info *lookup_name,
214 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
215 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
216 enum search_domain kind) = 0;
217
218 /* Return the comp unit from OBJFILE that contains PC and
219 SECTION. Return NULL if there is no such compunit. This
220 should return the compunit that contains a symbol whose
221 address exactly matches PC, or, if there is no exact match, the
222 compunit that contains a symbol whose address is closest to
223 PC. */
224 virtual struct compunit_symtab *find_pc_sect_compunit_symtab
225 (struct objfile *objfile, struct bound_minimal_symbol msymbol,
226 CORE_ADDR pc, struct obj_section *section, int warn_if_readin) = 0;
227
228 /* Return the comp unit from OBJFILE that contains a symbol at
229 ADDRESS. Return NULL if there is no such comp unit. Unlike
230 find_pc_sect_compunit_symtab, any sort of symbol (not just text
231 symbols) can be considered, and only exact address matches are
232 considered. */
233 virtual struct compunit_symtab *find_compunit_symtab_by_address
234 (struct objfile *objfile, CORE_ADDR address) = 0;
235
236 /* Call a callback for every file defined in OBJFILE whose symtab is
237 not already read in. FUN is the callback. It is passed the
238 file's FILENAME and the file's FULLNAME (if need_fullname is
239 non-zero). */
240 virtual void map_symbol_filenames
241 (struct objfile *objfile,
242 gdb::function_view<symbol_filename_ftype> fun,
243 bool need_fullname) = 0;
244
245 /* This is called when the objfile is relocated. It can be used to
246 clean up any internal caches. */
247 virtual void relocated ()
248 {
249 /* Do nothing. */
250 }
251
252 /* Return true if this class can lazily read the symbols. This may
253 only return true if there are in fact symbols to be read, because
254 this is used in the implementation of 'has_partial_symbols'. */
255 virtual bool can_lazily_read_symbols ()
256 {
257 return false;
258 }
259
260 /* Read the partial symbols for OBJFILE. This will only ever be
261 called if can_lazily_read_symbols returns true. */
262 virtual void read_partial_symbols (struct objfile *objfile)
263 {
264 }
265 };
266
267 typedef std::unique_ptr<quick_symbol_functions> quick_symbol_functions_up;
268
269 #endif /* GDB_QUICK_SYMBOL_H */