Commit | Line | Data |
---|---|---|
8fb8eb5c DE |
1 | /* Debug logging for the symbol file functions for the GNU debugger, GDB. |
2 | ||
61baf725 | 3 | Copyright (C) 2013-2017 Free Software Foundation, Inc. |
8fb8eb5c DE |
4 | |
5 | Contributed by Cygnus Support, using pieces from other GDB modules. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 3 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | /* Note: Be careful with functions that can throw errors. | |
23 | We want to see a logging message regardless of whether an error was thrown. | |
24 | This typically means printing a message before calling the real function | |
25 | and then if the function returns a result printing a message after it | |
26 | returns. */ | |
27 | ||
28 | #include "defs.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "objfiles.h" | |
31 | #include "observer.h" | |
32 | #include "source.h" | |
33 | #include "symtab.h" | |
34 | #include "symfile.h" | |
35 | ||
36 | /* We need to save a pointer to the real symbol functions. | |
37 | Plus, the debug versions are malloc'd because we have to NULL out the | |
38 | ones that are NULL in the real copy. */ | |
39 | ||
40 | struct debug_sym_fns_data | |
41 | { | |
42 | const struct sym_fns *real_sf; | |
43 | struct sym_fns debug_sf; | |
44 | }; | |
45 | ||
46 | /* We need to record a pointer to the real set of functions for each | |
47 | objfile. */ | |
48 | static const struct objfile_data *symfile_debug_objfile_data_key; | |
49 | ||
50 | /* If non-zero all calls to the symfile functions are logged. */ | |
51 | static int debug_symfile = 0; | |
52 | ||
53 | /* Return non-zero if symfile debug logging is installed. */ | |
54 | ||
55 | static int | |
56 | symfile_debug_installed (struct objfile *objfile) | |
57 | { | |
58 | return (objfile->sf != NULL | |
59 | && objfile_data (objfile, symfile_debug_objfile_data_key) != NULL); | |
60 | } | |
61 | ||
8fb8eb5c DE |
62 | /* Utility return the name to print for SYMTAB. */ |
63 | ||
64 | static const char * | |
65 | debug_symtab_name (struct symtab *symtab) | |
66 | { | |
67 | return symtab_to_filename_for_display (symtab); | |
68 | } | |
69 | \f | |
70 | /* Debugging version of struct quick_symbol_functions. */ | |
71 | ||
72 | static int | |
73 | debug_qf_has_symbols (struct objfile *objfile) | |
74 | { | |
19ba03f4 SM |
75 | const struct debug_sym_fns_data *debug_data |
76 | = ((const struct debug_sym_fns_data *) | |
77 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
78 | int retval; |
79 | ||
80 | retval = debug_data->real_sf->qf->has_symbols (objfile); | |
81 | ||
82 | fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n", | |
cc485e62 | 83 | objfile_debug_name (objfile), retval); |
8fb8eb5c DE |
84 | |
85 | return retval; | |
86 | } | |
87 | ||
88 | static struct symtab * | |
89 | debug_qf_find_last_source_symtab (struct objfile *objfile) | |
90 | { | |
19ba03f4 SM |
91 | const struct debug_sym_fns_data *debug_data |
92 | = ((const struct debug_sym_fns_data *) | |
93 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
94 | struct symtab *retval; |
95 | ||
96 | fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n", | |
cc485e62 | 97 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
98 | |
99 | retval = debug_data->real_sf->qf->find_last_source_symtab (objfile); | |
100 | ||
101 | fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n", | |
102 | retval ? debug_symtab_name (retval) : "NULL"); | |
103 | ||
104 | return retval; | |
105 | } | |
106 | ||
107 | static void | |
108 | debug_qf_forget_cached_source_info (struct objfile *objfile) | |
109 | { | |
19ba03f4 SM |
110 | const struct debug_sym_fns_data *debug_data |
111 | = ((const struct debug_sym_fns_data *) | |
112 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
113 | |
114 | fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n", | |
cc485e62 | 115 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
116 | |
117 | debug_data->real_sf->qf->forget_cached_source_info (objfile); | |
118 | } | |
119 | ||
14bc53a8 PA |
120 | static bool |
121 | debug_qf_map_symtabs_matching_filename | |
122 | (struct objfile *objfile, const char *name, const char *real_path, | |
123 | gdb::function_view<bool (symtab *)> callback) | |
8fb8eb5c | 124 | { |
19ba03f4 SM |
125 | const struct debug_sym_fns_data *debug_data |
126 | = ((const struct debug_sym_fns_data *) | |
127 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
128 | |
129 | fprintf_filtered (gdb_stdlog, | |
14bc53a8 | 130 | "qf->map_symtabs_matching_filename (%s, \"%s\", \"%s\", %s)\n", |
cc485e62 | 131 | objfile_debug_name (objfile), name, |
8fb8eb5c | 132 | real_path ? real_path : NULL, |
14bc53a8 | 133 | host_address_to_string (&callback)); |
8fb8eb5c | 134 | |
14bc53a8 PA |
135 | bool retval = (debug_data->real_sf->qf->map_symtabs_matching_filename |
136 | (objfile, name, real_path, callback)); | |
8fb8eb5c DE |
137 | |
138 | fprintf_filtered (gdb_stdlog, | |
139 | "qf->map_symtabs_matching_filename (...) = %d\n", | |
140 | retval); | |
141 | ||
142 | return retval; | |
143 | } | |
144 | ||
43f3e411 | 145 | static struct compunit_symtab * |
8fb8eb5c DE |
146 | debug_qf_lookup_symbol (struct objfile *objfile, int kind, const char *name, |
147 | domain_enum domain) | |
148 | { | |
19ba03f4 SM |
149 | const struct debug_sym_fns_data *debug_data |
150 | = ((const struct debug_sym_fns_data *) | |
151 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
43f3e411 | 152 | struct compunit_symtab *retval; |
8fb8eb5c DE |
153 | |
154 | fprintf_filtered (gdb_stdlog, | |
155 | "qf->lookup_symbol (%s, %d, \"%s\", %s)\n", | |
cc485e62 | 156 | objfile_debug_name (objfile), kind, name, |
8fb8eb5c DE |
157 | domain_name (domain)); |
158 | ||
159 | retval = debug_data->real_sf->qf->lookup_symbol (objfile, kind, name, | |
160 | domain); | |
161 | ||
162 | fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n", | |
43f3e411 DE |
163 | retval |
164 | ? debug_symtab_name (compunit_primary_filetab (retval)) | |
165 | : "NULL"); | |
8fb8eb5c DE |
166 | |
167 | return retval; | |
168 | } | |
169 | ||
170 | static void | |
171 | debug_qf_print_stats (struct objfile *objfile) | |
172 | { | |
19ba03f4 SM |
173 | const struct debug_sym_fns_data *debug_data |
174 | = ((const struct debug_sym_fns_data *) | |
175 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
176 | |
177 | fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n", | |
cc485e62 | 178 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
179 | |
180 | debug_data->real_sf->qf->print_stats (objfile); | |
181 | } | |
182 | ||
183 | static void | |
184 | debug_qf_dump (struct objfile *objfile) | |
185 | { | |
19ba03f4 SM |
186 | const struct debug_sym_fns_data *debug_data |
187 | = ((const struct debug_sym_fns_data *) | |
188 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
189 | |
190 | fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n", | |
cc485e62 | 191 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
192 | |
193 | debug_data->real_sf->qf->dump (objfile); | |
194 | } | |
195 | ||
196 | static void | |
197 | debug_qf_relocate (struct objfile *objfile, | |
198 | const struct section_offsets *new_offsets, | |
199 | const struct section_offsets *delta) | |
200 | { | |
19ba03f4 SM |
201 | const struct debug_sym_fns_data *debug_data |
202 | = ((const struct debug_sym_fns_data *) | |
203 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
204 | |
205 | fprintf_filtered (gdb_stdlog, "qf->relocate (%s, %s, %s)\n", | |
cc485e62 | 206 | objfile_debug_name (objfile), |
8fb8eb5c DE |
207 | host_address_to_string (new_offsets), |
208 | host_address_to_string (delta)); | |
209 | ||
210 | debug_data->real_sf->qf->relocate (objfile, new_offsets, delta); | |
211 | } | |
212 | ||
213 | static void | |
214 | debug_qf_expand_symtabs_for_function (struct objfile *objfile, | |
215 | const char *func_name) | |
216 | { | |
19ba03f4 SM |
217 | const struct debug_sym_fns_data *debug_data |
218 | = ((const struct debug_sym_fns_data *) | |
219 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
220 | |
221 | fprintf_filtered (gdb_stdlog, | |
222 | "qf->expand_symtabs_for_function (%s, \"%s\")\n", | |
cc485e62 | 223 | objfile_debug_name (objfile), func_name); |
8fb8eb5c DE |
224 | |
225 | debug_data->real_sf->qf->expand_symtabs_for_function (objfile, func_name); | |
226 | } | |
227 | ||
228 | static void | |
229 | debug_qf_expand_all_symtabs (struct objfile *objfile) | |
230 | { | |
19ba03f4 SM |
231 | const struct debug_sym_fns_data *debug_data |
232 | = ((const struct debug_sym_fns_data *) | |
233 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
234 | |
235 | fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n", | |
cc485e62 | 236 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
237 | |
238 | debug_data->real_sf->qf->expand_all_symtabs (objfile); | |
239 | } | |
240 | ||
241 | static void | |
242 | debug_qf_expand_symtabs_with_fullname (struct objfile *objfile, | |
243 | const char *fullname) | |
244 | { | |
19ba03f4 SM |
245 | const struct debug_sym_fns_data *debug_data |
246 | = ((const struct debug_sym_fns_data *) | |
247 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
248 | |
249 | fprintf_filtered (gdb_stdlog, | |
250 | "qf->expand_symtabs_with_fullname (%s, \"%s\")\n", | |
cc485e62 | 251 | objfile_debug_name (objfile), fullname); |
8fb8eb5c DE |
252 | |
253 | debug_data->real_sf->qf->expand_symtabs_with_fullname (objfile, fullname); | |
254 | } | |
255 | ||
256 | static void | |
257 | debug_qf_map_matching_symbols (struct objfile *objfile, | |
fe978cb0 | 258 | const char *name, domain_enum domain, |
8fb8eb5c DE |
259 | int global, |
260 | int (*callback) (struct block *, | |
261 | struct symbol *, void *), | |
262 | void *data, | |
263 | symbol_compare_ftype *match, | |
264 | symbol_compare_ftype *ordered_compare) | |
265 | { | |
19ba03f4 SM |
266 | const struct debug_sym_fns_data *debug_data |
267 | = ((const struct debug_sym_fns_data *) | |
268 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
269 | |
270 | fprintf_filtered (gdb_stdlog, | |
271 | "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n", | |
cc485e62 | 272 | objfile_debug_name (objfile), name, |
fe978cb0 | 273 | domain_name (domain), global, |
8fb8eb5c DE |
274 | host_address_to_string (callback), |
275 | host_address_to_string (data), | |
276 | host_address_to_string (match), | |
277 | host_address_to_string (ordered_compare)); | |
278 | ||
279 | debug_data->real_sf->qf->map_matching_symbols (objfile, name, | |
fe978cb0 | 280 | domain, global, |
8fb8eb5c DE |
281 | callback, data, |
282 | match, | |
283 | ordered_compare); | |
284 | } | |
285 | ||
286 | static void | |
e86b67d3 JB |
287 | debug_qf_expand_symtabs_matching |
288 | (struct objfile *objfile, | |
14bc53a8 PA |
289 | gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher, |
290 | gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher, | |
291 | gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify, | |
292 | enum search_domain kind) | |
8fb8eb5c | 293 | { |
19ba03f4 SM |
294 | const struct debug_sym_fns_data *debug_data |
295 | = ((const struct debug_sym_fns_data *) | |
296 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
297 | |
298 | fprintf_filtered (gdb_stdlog, | |
14bc53a8 | 299 | "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n", |
cc485e62 | 300 | objfile_debug_name (objfile), |
14bc53a8 PA |
301 | host_address_to_string (&file_matcher), |
302 | host_address_to_string (&symbol_matcher), | |
303 | host_address_to_string (&expansion_notify), | |
304 | search_domain_name (kind)); | |
8fb8eb5c DE |
305 | |
306 | debug_data->real_sf->qf->expand_symtabs_matching (objfile, | |
307 | file_matcher, | |
3f03e7b1 | 308 | symbol_matcher, |
276d885b | 309 | expansion_notify, |
14bc53a8 | 310 | kind); |
8fb8eb5c DE |
311 | } |
312 | ||
43f3e411 DE |
313 | static struct compunit_symtab * |
314 | debug_qf_find_pc_sect_compunit_symtab (struct objfile *objfile, | |
315 | struct bound_minimal_symbol msymbol, | |
316 | CORE_ADDR pc, | |
317 | struct obj_section *section, | |
318 | int warn_if_readin) | |
8fb8eb5c | 319 | { |
19ba03f4 SM |
320 | const struct debug_sym_fns_data *debug_data |
321 | = ((const struct debug_sym_fns_data *) | |
322 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
43f3e411 | 323 | struct compunit_symtab *retval; |
8fb8eb5c DE |
324 | |
325 | fprintf_filtered (gdb_stdlog, | |
43f3e411 | 326 | "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n", |
cc485e62 | 327 | objfile_debug_name (objfile), |
77e371c0 | 328 | host_address_to_string (msymbol.minsym), |
8fb8eb5c DE |
329 | hex_string (pc), |
330 | host_address_to_string (section), | |
331 | warn_if_readin); | |
332 | ||
43f3e411 DE |
333 | retval |
334 | = debug_data->real_sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol, | |
335 | pc, section, | |
336 | warn_if_readin); | |
8fb8eb5c | 337 | |
43f3e411 DE |
338 | fprintf_filtered (gdb_stdlog, |
339 | "qf->find_pc_sect_compunit_symtab (...) = %s\n", | |
340 | retval | |
341 | ? debug_symtab_name (compunit_primary_filetab (retval)) | |
342 | : "NULL"); | |
8fb8eb5c DE |
343 | |
344 | return retval; | |
345 | } | |
346 | ||
347 | static void | |
348 | debug_qf_map_symbol_filenames (struct objfile *objfile, | |
349 | symbol_filename_ftype *fun, void *data, | |
350 | int need_fullname) | |
351 | { | |
19ba03f4 SM |
352 | const struct debug_sym_fns_data *debug_data |
353 | = ((const struct debug_sym_fns_data *) | |
354 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
355 | fprintf_filtered (gdb_stdlog, |
356 | "qf->map_symbol_filenames (%s, %s, %s, %d)\n", | |
cc485e62 | 357 | objfile_debug_name (objfile), |
8fb8eb5c DE |
358 | host_address_to_string (fun), |
359 | host_address_to_string (data), | |
360 | need_fullname); | |
361 | ||
362 | debug_data->real_sf->qf->map_symbol_filenames (objfile, fun, data, | |
363 | need_fullname); | |
364 | } | |
365 | ||
366 | static const struct quick_symbol_functions debug_sym_quick_functions = | |
367 | { | |
368 | debug_qf_has_symbols, | |
369 | debug_qf_find_last_source_symtab, | |
370 | debug_qf_forget_cached_source_info, | |
371 | debug_qf_map_symtabs_matching_filename, | |
372 | debug_qf_lookup_symbol, | |
373 | debug_qf_print_stats, | |
374 | debug_qf_dump, | |
375 | debug_qf_relocate, | |
376 | debug_qf_expand_symtabs_for_function, | |
377 | debug_qf_expand_all_symtabs, | |
378 | debug_qf_expand_symtabs_with_fullname, | |
379 | debug_qf_map_matching_symbols, | |
380 | debug_qf_expand_symtabs_matching, | |
43f3e411 | 381 | debug_qf_find_pc_sect_compunit_symtab, |
8fb8eb5c DE |
382 | debug_qf_map_symbol_filenames |
383 | }; | |
384 | \f | |
385 | /* Debugging version of struct sym_probe_fns. */ | |
386 | ||
387 | static VEC (probe_p) * | |
388 | debug_sym_get_probes (struct objfile *objfile) | |
389 | { | |
19ba03f4 SM |
390 | const struct debug_sym_fns_data *debug_data |
391 | = ((const struct debug_sym_fns_data *) | |
392 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
393 | VEC (probe_p) *retval; |
394 | ||
395 | retval = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile); | |
396 | ||
397 | fprintf_filtered (gdb_stdlog, | |
398 | "probes->sym_get_probes (%s) = %s\n", | |
cc485e62 | 399 | objfile_debug_name (objfile), |
8fb8eb5c DE |
400 | host_address_to_string (retval)); |
401 | ||
402 | return retval; | |
403 | } | |
404 | ||
8fb8eb5c DE |
405 | static const struct sym_probe_fns debug_sym_probe_fns = |
406 | { | |
407 | debug_sym_get_probes, | |
8fb8eb5c DE |
408 | }; |
409 | \f | |
410 | /* Debugging version of struct sym_fns. */ | |
411 | ||
412 | static void | |
413 | debug_sym_new_init (struct objfile *objfile) | |
414 | { | |
19ba03f4 SM |
415 | const struct debug_sym_fns_data *debug_data |
416 | = ((const struct debug_sym_fns_data *) | |
417 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
418 | |
419 | fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n", | |
cc485e62 | 420 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
421 | |
422 | debug_data->real_sf->sym_new_init (objfile); | |
423 | } | |
424 | ||
425 | static void | |
426 | debug_sym_init (struct objfile *objfile) | |
427 | { | |
19ba03f4 SM |
428 | const struct debug_sym_fns_data *debug_data |
429 | = ((const struct debug_sym_fns_data *) | |
430 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
431 | |
432 | fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n", | |
cc485e62 | 433 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
434 | |
435 | debug_data->real_sf->sym_init (objfile); | |
436 | } | |
437 | ||
438 | static void | |
b15cc25c | 439 | debug_sym_read (struct objfile *objfile, symfile_add_flags symfile_flags) |
8fb8eb5c | 440 | { |
19ba03f4 SM |
441 | const struct debug_sym_fns_data *debug_data |
442 | = ((const struct debug_sym_fns_data *) | |
443 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
444 | |
445 | fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n", | |
b15cc25c | 446 | objfile_debug_name (objfile), (unsigned) symfile_flags); |
8fb8eb5c DE |
447 | |
448 | debug_data->real_sf->sym_read (objfile, symfile_flags); | |
449 | } | |
450 | ||
451 | static void | |
452 | debug_sym_read_psymbols (struct objfile *objfile) | |
453 | { | |
19ba03f4 SM |
454 | const struct debug_sym_fns_data *debug_data |
455 | = ((const struct debug_sym_fns_data *) | |
456 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
457 | |
458 | fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n", | |
cc485e62 | 459 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
460 | |
461 | debug_data->real_sf->sym_read_psymbols (objfile); | |
462 | } | |
463 | ||
464 | static void | |
465 | debug_sym_finish (struct objfile *objfile) | |
466 | { | |
19ba03f4 SM |
467 | const struct debug_sym_fns_data *debug_data |
468 | = ((const struct debug_sym_fns_data *) | |
469 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
470 | |
471 | fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n", | |
cc485e62 | 472 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
473 | |
474 | debug_data->real_sf->sym_finish (objfile); | |
475 | } | |
476 | ||
477 | static void | |
478 | debug_sym_offsets (struct objfile *objfile, | |
479 | const struct section_addr_info *info) | |
480 | { | |
19ba03f4 SM |
481 | const struct debug_sym_fns_data *debug_data |
482 | = ((const struct debug_sym_fns_data *) | |
483 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
484 | |
485 | fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n", | |
cc485e62 | 486 | objfile_debug_name (objfile), |
8fb8eb5c DE |
487 | host_address_to_string (info)); |
488 | ||
489 | debug_data->real_sf->sym_offsets (objfile, info); | |
490 | } | |
491 | ||
492 | static struct symfile_segment_data * | |
493 | debug_sym_segments (bfd *abfd) | |
494 | { | |
495 | /* This API function is annoying, it doesn't take a "this" pointer. | |
496 | Fortunately it is only used in one place where we (re-)lookup the | |
497 | sym_fns table to use. Thus we will never be called. */ | |
498 | gdb_assert_not_reached ("debug_sym_segments called"); | |
499 | } | |
500 | ||
501 | static void | |
502 | debug_sym_read_linetable (struct objfile *objfile) | |
503 | { | |
19ba03f4 SM |
504 | const struct debug_sym_fns_data *debug_data |
505 | = ((const struct debug_sym_fns_data *) | |
506 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
507 | |
508 | fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n", | |
cc485e62 | 509 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
510 | |
511 | debug_data->real_sf->sym_read_linetable (objfile); | |
512 | } | |
513 | ||
514 | static bfd_byte * | |
515 | debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf) | |
516 | { | |
19ba03f4 SM |
517 | const struct debug_sym_fns_data *debug_data |
518 | = ((const struct debug_sym_fns_data *) | |
519 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
520 | bfd_byte *retval; |
521 | ||
522 | retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf); | |
523 | ||
524 | fprintf_filtered (gdb_stdlog, | |
525 | "sf->sym_relocate (%s, %s, %s) = %s\n", | |
cc485e62 | 526 | objfile_debug_name (objfile), |
8fb8eb5c DE |
527 | host_address_to_string (sectp), |
528 | host_address_to_string (buf), | |
529 | host_address_to_string (retval)); | |
530 | ||
531 | return retval; | |
532 | } | |
533 | ||
534 | /* Template of debugging version of struct sym_fns. | |
535 | A copy is made, with sym_flavour updated, and a pointer to the real table | |
536 | installed in real_sf, and then a pointer to the copy is installed in the | |
537 | objfile. */ | |
538 | ||
539 | static const struct sym_fns debug_sym_fns = | |
540 | { | |
541 | debug_sym_new_init, | |
542 | debug_sym_init, | |
543 | debug_sym_read, | |
544 | debug_sym_read_psymbols, | |
545 | debug_sym_finish, | |
546 | debug_sym_offsets, | |
547 | debug_sym_segments, | |
548 | debug_sym_read_linetable, | |
549 | debug_sym_relocate, | |
550 | &debug_sym_probe_fns, | |
551 | &debug_sym_quick_functions | |
552 | }; | |
553 | \f | |
554 | /* Free the copy of sym_fns recorded in the registry. */ | |
555 | ||
556 | static void | |
557 | symfile_debug_free_objfile (struct objfile *objfile, void *datum) | |
558 | { | |
559 | xfree (datum); | |
560 | } | |
561 | ||
562 | /* Install the debugging versions of the symfile functions for OBJFILE. | |
563 | Do not call this if the debug versions are already installed. */ | |
564 | ||
565 | static void | |
566 | install_symfile_debug_logging (struct objfile *objfile) | |
567 | { | |
568 | const struct sym_fns *real_sf; | |
569 | struct debug_sym_fns_data *debug_data; | |
570 | ||
571 | /* The debug versions should not already be installed. */ | |
572 | gdb_assert (!symfile_debug_installed (objfile)); | |
573 | ||
574 | real_sf = objfile->sf; | |
575 | ||
576 | /* Alas we have to preserve NULL entries in REAL_SF. */ | |
41bf6aca | 577 | debug_data = XCNEW (struct debug_sym_fns_data); |
8fb8eb5c DE |
578 | |
579 | #define COPY_SF_PTR(from, to, name, func) \ | |
580 | do { \ | |
581 | if ((from)->name) \ | |
582 | (to)->debug_sf.name = func; \ | |
583 | } while (0) | |
584 | ||
585 | COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init); | |
586 | COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init); | |
587 | COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read); | |
588 | COPY_SF_PTR (real_sf, debug_data, sym_read_psymbols, | |
589 | debug_sym_read_psymbols); | |
590 | COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish); | |
591 | COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets); | |
592 | COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments); | |
593 | COPY_SF_PTR (real_sf, debug_data, sym_read_linetable, | |
594 | debug_sym_read_linetable); | |
595 | COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate); | |
596 | if (real_sf->sym_probe_fns) | |
597 | debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns; | |
598 | debug_data->debug_sf.qf = &debug_sym_quick_functions; | |
599 | ||
600 | #undef COPY_SF_PTR | |
601 | ||
602 | debug_data->real_sf = real_sf; | |
603 | set_objfile_data (objfile, symfile_debug_objfile_data_key, debug_data); | |
604 | objfile->sf = &debug_data->debug_sf; | |
605 | } | |
606 | ||
607 | /* Uninstall the debugging versions of the symfile functions for OBJFILE. | |
608 | Do not call this if the debug versions are not installed. */ | |
609 | ||
610 | static void | |
611 | uninstall_symfile_debug_logging (struct objfile *objfile) | |
612 | { | |
613 | struct debug_sym_fns_data *debug_data; | |
614 | ||
615 | /* The debug versions should be currently installed. */ | |
616 | gdb_assert (symfile_debug_installed (objfile)); | |
617 | ||
19ba03f4 SM |
618 | debug_data = ((struct debug_sym_fns_data *) |
619 | objfile_data (objfile, symfile_debug_objfile_data_key)); | |
8fb8eb5c DE |
620 | |
621 | objfile->sf = debug_data->real_sf; | |
622 | xfree (debug_data); | |
623 | set_objfile_data (objfile, symfile_debug_objfile_data_key, NULL); | |
624 | } | |
625 | ||
626 | /* Call this function to set OBJFILE->SF. | |
627 | Do not set OBJFILE->SF directly. */ | |
628 | ||
629 | void | |
630 | objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf) | |
631 | { | |
632 | if (symfile_debug_installed (objfile)) | |
633 | { | |
634 | gdb_assert (debug_symfile); | |
635 | /* Remove the current one, and reinstall a new one later. */ | |
636 | uninstall_symfile_debug_logging (objfile); | |
637 | } | |
638 | ||
639 | /* Assume debug logging is disabled. */ | |
640 | objfile->sf = sf; | |
641 | ||
642 | /* Turn debug logging on if enabled. */ | |
643 | if (debug_symfile) | |
644 | install_symfile_debug_logging (objfile); | |
645 | } | |
646 | ||
647 | static void | |
648 | set_debug_symfile (char *args, int from_tty, struct cmd_list_element *c) | |
649 | { | |
650 | struct program_space *pspace; | |
651 | struct objfile *objfile; | |
652 | ||
653 | ALL_PSPACES (pspace) | |
654 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
655 | { | |
656 | if (debug_symfile) | |
657 | { | |
658 | if (!symfile_debug_installed (objfile)) | |
659 | install_symfile_debug_logging (objfile); | |
660 | } | |
661 | else | |
662 | { | |
663 | if (symfile_debug_installed (objfile)) | |
664 | uninstall_symfile_debug_logging (objfile); | |
665 | } | |
666 | } | |
667 | } | |
668 | ||
669 | static void | |
670 | show_debug_symfile (struct ui_file *file, int from_tty, | |
671 | struct cmd_list_element *c, const char *value) | |
672 | { | |
673 | fprintf_filtered (file, _("Symfile debugging is %s.\n"), value); | |
674 | } | |
675 | ||
676 | initialize_file_ftype _initialize_symfile_debug; | |
677 | ||
678 | void | |
679 | _initialize_symfile_debug (void) | |
680 | { | |
681 | symfile_debug_objfile_data_key | |
682 | = register_objfile_data_with_cleanup (NULL, symfile_debug_free_objfile); | |
683 | ||
684 | add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\ | |
685 | Set debugging of the symfile functions."), _("\ | |
686 | Show debugging of the symfile functions."), _("\ | |
687 | When enabled, all calls to the symfile functions are logged."), | |
688 | set_debug_symfile, show_debug_symfile, | |
689 | &setdebuglist, &showdebuglist); | |
690 | ||
691 | /* Note: We don't need a new-objfile observer because debug logging | |
692 | will be installed when objfile init'n calls objfile_set_sym_fns. */ | |
693 | } |