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