1 /* Debug logging for the symbol file functions for the GNU debugger, GDB.
3 Copyright (C) 2013-2015 Free Software Foundation, Inc.
5 Contributed by Cygnus Support, using pieces from other GDB modules.
7 This file is part of GDB.
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.
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.
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/>. */
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
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. */
40 struct debug_sym_fns_data
42 const struct sym_fns *real_sf;
43 struct sym_fns debug_sf;
46 /* We need to record a pointer to the real set of functions for each
48 static const struct objfile_data *symfile_debug_objfile_data_key;
50 /* If non-zero all calls to the symfile functions are logged. */
51 static int debug_symfile = 0;
53 /* Return non-zero if symfile debug logging is installed. */
56 symfile_debug_installed (struct objfile *objfile)
58 return (objfile->sf != NULL
59 && objfile_data (objfile, symfile_debug_objfile_data_key) != NULL);
62 /* Utility return the name to print for SYMTAB. */
65 debug_symtab_name (struct symtab *symtab)
67 return symtab_to_filename_for_display (symtab);
70 /* Debugging version of struct quick_symbol_functions. */
73 debug_qf_has_symbols (struct objfile *objfile)
75 const struct debug_sym_fns_data *debug_data =
76 objfile_data (objfile, symfile_debug_objfile_data_key);
79 retval = debug_data->real_sf->qf->has_symbols (objfile);
81 fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n",
82 objfile_debug_name (objfile), retval);
87 static struct symtab *
88 debug_qf_find_last_source_symtab (struct objfile *objfile)
90 const struct debug_sym_fns_data *debug_data =
91 objfile_data (objfile, symfile_debug_objfile_data_key);
92 struct symtab *retval;
94 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
95 objfile_debug_name (objfile));
97 retval = debug_data->real_sf->qf->find_last_source_symtab (objfile);
99 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n",
100 retval ? debug_symtab_name (retval) : "NULL");
106 debug_qf_forget_cached_source_info (struct objfile *objfile)
108 const struct debug_sym_fns_data *debug_data =
109 objfile_data (objfile, symfile_debug_objfile_data_key);
111 fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
112 objfile_debug_name (objfile));
114 debug_data->real_sf->qf->forget_cached_source_info (objfile);
118 debug_qf_map_symtabs_matching_filename (struct objfile *objfile,
120 const char *real_path,
121 int (*callback) (struct symtab *,
125 const struct debug_sym_fns_data *debug_data =
126 objfile_data (objfile, symfile_debug_objfile_data_key);
129 fprintf_filtered (gdb_stdlog,
130 "qf->map_symtabs_matching_filename (%s, \"%s\", \"%s\", %s, %s)\n",
131 objfile_debug_name (objfile), name,
132 real_path ? real_path : NULL,
133 host_address_to_string (callback),
134 host_address_to_string (data));
136 retval = debug_data->real_sf->qf->map_symtabs_matching_filename
137 (objfile, name, real_path, callback, data);
139 fprintf_filtered (gdb_stdlog,
140 "qf->map_symtabs_matching_filename (...) = %d\n",
146 static struct compunit_symtab *
147 debug_qf_lookup_symbol (struct objfile *objfile, int kind, const char *name,
150 const struct debug_sym_fns_data *debug_data =
151 objfile_data (objfile, symfile_debug_objfile_data_key);
152 struct compunit_symtab *retval;
154 fprintf_filtered (gdb_stdlog,
155 "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
156 objfile_debug_name (objfile), kind, name,
157 domain_name (domain));
159 retval = debug_data->real_sf->qf->lookup_symbol (objfile, kind, name,
162 fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
164 ? debug_symtab_name (compunit_primary_filetab (retval))
171 debug_qf_print_stats (struct objfile *objfile)
173 const struct debug_sym_fns_data *debug_data =
174 objfile_data (objfile, symfile_debug_objfile_data_key);
176 fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
177 objfile_debug_name (objfile));
179 debug_data->real_sf->qf->print_stats (objfile);
183 debug_qf_dump (struct objfile *objfile)
185 const struct debug_sym_fns_data *debug_data =
186 objfile_data (objfile, symfile_debug_objfile_data_key);
188 fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
189 objfile_debug_name (objfile));
191 debug_data->real_sf->qf->dump (objfile);
195 debug_qf_relocate (struct objfile *objfile,
196 const struct section_offsets *new_offsets,
197 const struct section_offsets *delta)
199 const struct debug_sym_fns_data *debug_data =
200 objfile_data (objfile, symfile_debug_objfile_data_key);
202 fprintf_filtered (gdb_stdlog, "qf->relocate (%s, %s, %s)\n",
203 objfile_debug_name (objfile),
204 host_address_to_string (new_offsets),
205 host_address_to_string (delta));
207 debug_data->real_sf->qf->relocate (objfile, new_offsets, delta);
211 debug_qf_expand_symtabs_for_function (struct objfile *objfile,
212 const char *func_name)
214 const struct debug_sym_fns_data *debug_data =
215 objfile_data (objfile, symfile_debug_objfile_data_key);
217 fprintf_filtered (gdb_stdlog,
218 "qf->expand_symtabs_for_function (%s, \"%s\")\n",
219 objfile_debug_name (objfile), func_name);
221 debug_data->real_sf->qf->expand_symtabs_for_function (objfile, func_name);
225 debug_qf_expand_all_symtabs (struct objfile *objfile)
227 const struct debug_sym_fns_data *debug_data =
228 objfile_data (objfile, symfile_debug_objfile_data_key);
230 fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
231 objfile_debug_name (objfile));
233 debug_data->real_sf->qf->expand_all_symtabs (objfile);
237 debug_qf_expand_symtabs_with_fullname (struct objfile *objfile,
238 const char *fullname)
240 const struct debug_sym_fns_data *debug_data =
241 objfile_data (objfile, symfile_debug_objfile_data_key);
243 fprintf_filtered (gdb_stdlog,
244 "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
245 objfile_debug_name (objfile), fullname);
247 debug_data->real_sf->qf->expand_symtabs_with_fullname (objfile, fullname);
251 debug_qf_map_matching_symbols (struct objfile *objfile,
252 const char *name, domain_enum namespace,
254 int (*callback) (struct block *,
255 struct symbol *, void *),
257 symbol_compare_ftype *match,
258 symbol_compare_ftype *ordered_compare)
260 const struct debug_sym_fns_data *debug_data =
261 objfile_data (objfile, symfile_debug_objfile_data_key);
263 fprintf_filtered (gdb_stdlog,
264 "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n",
265 objfile_debug_name (objfile), name,
266 domain_name (namespace), global,
267 host_address_to_string (callback),
268 host_address_to_string (data),
269 host_address_to_string (match),
270 host_address_to_string (ordered_compare));
272 debug_data->real_sf->qf->map_matching_symbols (objfile, name,
280 debug_qf_expand_symtabs_matching
281 (struct objfile *objfile,
282 expand_symtabs_file_matcher_ftype *file_matcher,
283 expand_symtabs_symbol_matcher_ftype *symbol_matcher,
284 expand_symtabs_exp_notify_ftype *expansion_notify,
285 enum search_domain kind, void *data)
287 const struct debug_sym_fns_data *debug_data =
288 objfile_data (objfile, symfile_debug_objfile_data_key);
290 fprintf_filtered (gdb_stdlog,
291 "qf->expand_symtabs_matching (%s, %s, %s, %s, %s, %s)\n",
292 objfile_debug_name (objfile),
293 host_address_to_string (file_matcher),
294 host_address_to_string (symbol_matcher),
295 host_address_to_string (expansion_notify),
296 search_domain_name (kind),
297 host_address_to_string (data));
299 debug_data->real_sf->qf->expand_symtabs_matching (objfile,
306 static struct compunit_symtab *
307 debug_qf_find_pc_sect_compunit_symtab (struct objfile *objfile,
308 struct bound_minimal_symbol msymbol,
310 struct obj_section *section,
313 const struct debug_sym_fns_data *debug_data =
314 objfile_data (objfile, symfile_debug_objfile_data_key);
315 struct compunit_symtab *retval;
317 fprintf_filtered (gdb_stdlog,
318 "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n",
319 objfile_debug_name (objfile),
320 host_address_to_string (msymbol.minsym),
322 host_address_to_string (section),
326 = debug_data->real_sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol,
330 fprintf_filtered (gdb_stdlog,
331 "qf->find_pc_sect_compunit_symtab (...) = %s\n",
333 ? debug_symtab_name (compunit_primary_filetab (retval))
340 debug_qf_map_symbol_filenames (struct objfile *objfile,
341 symbol_filename_ftype *fun, void *data,
344 const struct debug_sym_fns_data *debug_data =
345 objfile_data (objfile, symfile_debug_objfile_data_key);
346 fprintf_filtered (gdb_stdlog,
347 "qf->map_symbol_filenames (%s, %s, %s, %d)\n",
348 objfile_debug_name (objfile),
349 host_address_to_string (fun),
350 host_address_to_string (data),
353 debug_data->real_sf->qf->map_symbol_filenames (objfile, fun, data,
357 static const struct quick_symbol_functions debug_sym_quick_functions =
359 debug_qf_has_symbols,
360 debug_qf_find_last_source_symtab,
361 debug_qf_forget_cached_source_info,
362 debug_qf_map_symtabs_matching_filename,
363 debug_qf_lookup_symbol,
364 debug_qf_print_stats,
367 debug_qf_expand_symtabs_for_function,
368 debug_qf_expand_all_symtabs,
369 debug_qf_expand_symtabs_with_fullname,
370 debug_qf_map_matching_symbols,
371 debug_qf_expand_symtabs_matching,
372 debug_qf_find_pc_sect_compunit_symtab,
373 debug_qf_map_symbol_filenames
376 /* Debugging version of struct sym_probe_fns. */
378 static VEC (probe_p) *
379 debug_sym_get_probes (struct objfile *objfile)
381 const struct debug_sym_fns_data *debug_data =
382 objfile_data (objfile, symfile_debug_objfile_data_key);
383 VEC (probe_p) *retval;
385 retval = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile);
387 fprintf_filtered (gdb_stdlog,
388 "probes->sym_get_probes (%s) = %s\n",
389 objfile_debug_name (objfile),
390 host_address_to_string (retval));
395 static const struct sym_probe_fns debug_sym_probe_fns =
397 debug_sym_get_probes,
400 /* Debugging version of struct sym_fns. */
403 debug_sym_new_init (struct objfile *objfile)
405 const struct debug_sym_fns_data *debug_data =
406 objfile_data (objfile, symfile_debug_objfile_data_key);
408 fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n",
409 objfile_debug_name (objfile));
411 debug_data->real_sf->sym_new_init (objfile);
415 debug_sym_init (struct objfile *objfile)
417 const struct debug_sym_fns_data *debug_data =
418 objfile_data (objfile, symfile_debug_objfile_data_key);
420 fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n",
421 objfile_debug_name (objfile));
423 debug_data->real_sf->sym_init (objfile);
427 debug_sym_read (struct objfile *objfile, int symfile_flags)
429 const struct debug_sym_fns_data *debug_data =
430 objfile_data (objfile, symfile_debug_objfile_data_key);
432 fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n",
433 objfile_debug_name (objfile), symfile_flags);
435 debug_data->real_sf->sym_read (objfile, symfile_flags);
439 debug_sym_read_psymbols (struct objfile *objfile)
441 const struct debug_sym_fns_data *debug_data =
442 objfile_data (objfile, symfile_debug_objfile_data_key);
444 fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n",
445 objfile_debug_name (objfile));
447 debug_data->real_sf->sym_read_psymbols (objfile);
451 debug_sym_finish (struct objfile *objfile)
453 const struct debug_sym_fns_data *debug_data =
454 objfile_data (objfile, symfile_debug_objfile_data_key);
456 fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n",
457 objfile_debug_name (objfile));
459 debug_data->real_sf->sym_finish (objfile);
463 debug_sym_offsets (struct objfile *objfile,
464 const struct section_addr_info *info)
466 const struct debug_sym_fns_data *debug_data =
467 objfile_data (objfile, symfile_debug_objfile_data_key);
469 fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n",
470 objfile_debug_name (objfile),
471 host_address_to_string (info));
473 debug_data->real_sf->sym_offsets (objfile, info);
476 static struct symfile_segment_data *
477 debug_sym_segments (bfd *abfd)
479 /* This API function is annoying, it doesn't take a "this" pointer.
480 Fortunately it is only used in one place where we (re-)lookup the
481 sym_fns table to use. Thus we will never be called. */
482 gdb_assert_not_reached ("debug_sym_segments called");
486 debug_sym_read_linetable (struct objfile *objfile)
488 const struct debug_sym_fns_data *debug_data =
489 objfile_data (objfile, symfile_debug_objfile_data_key);
491 fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n",
492 objfile_debug_name (objfile));
494 debug_data->real_sf->sym_read_linetable (objfile);
498 debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf)
500 const struct debug_sym_fns_data *debug_data =
501 objfile_data (objfile, symfile_debug_objfile_data_key);
504 retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf);
506 fprintf_filtered (gdb_stdlog,
507 "sf->sym_relocate (%s, %s, %s) = %s\n",
508 objfile_debug_name (objfile),
509 host_address_to_string (sectp),
510 host_address_to_string (buf),
511 host_address_to_string (retval));
516 /* Template of debugging version of struct sym_fns.
517 A copy is made, with sym_flavour updated, and a pointer to the real table
518 installed in real_sf, and then a pointer to the copy is installed in the
521 static const struct sym_fns debug_sym_fns =
526 debug_sym_read_psymbols,
530 debug_sym_read_linetable,
532 &debug_sym_probe_fns,
533 &debug_sym_quick_functions
536 /* Free the copy of sym_fns recorded in the registry. */
539 symfile_debug_free_objfile (struct objfile *objfile, void *datum)
544 /* Install the debugging versions of the symfile functions for OBJFILE.
545 Do not call this if the debug versions are already installed. */
548 install_symfile_debug_logging (struct objfile *objfile)
550 const struct sym_fns *real_sf;
551 struct debug_sym_fns_data *debug_data;
553 /* The debug versions should not already be installed. */
554 gdb_assert (!symfile_debug_installed (objfile));
556 real_sf = objfile->sf;
558 /* Alas we have to preserve NULL entries in REAL_SF. */
559 debug_data = XCNEW (struct debug_sym_fns_data);
561 #define COPY_SF_PTR(from, to, name, func) \
564 (to)->debug_sf.name = func; \
567 COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init);
568 COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init);
569 COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read);
570 COPY_SF_PTR (real_sf, debug_data, sym_read_psymbols,
571 debug_sym_read_psymbols);
572 COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish);
573 COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets);
574 COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments);
575 COPY_SF_PTR (real_sf, debug_data, sym_read_linetable,
576 debug_sym_read_linetable);
577 COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate);
578 if (real_sf->sym_probe_fns)
579 debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns;
580 debug_data->debug_sf.qf = &debug_sym_quick_functions;
584 debug_data->real_sf = real_sf;
585 set_objfile_data (objfile, symfile_debug_objfile_data_key, debug_data);
586 objfile->sf = &debug_data->debug_sf;
589 /* Uninstall the debugging versions of the symfile functions for OBJFILE.
590 Do not call this if the debug versions are not installed. */
593 uninstall_symfile_debug_logging (struct objfile *objfile)
595 struct debug_sym_fns_data *debug_data;
597 /* The debug versions should be currently installed. */
598 gdb_assert (symfile_debug_installed (objfile));
600 debug_data = objfile_data (objfile, symfile_debug_objfile_data_key);
602 objfile->sf = debug_data->real_sf;
604 set_objfile_data (objfile, symfile_debug_objfile_data_key, NULL);
607 /* Call this function to set OBJFILE->SF.
608 Do not set OBJFILE->SF directly. */
611 objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf)
613 if (symfile_debug_installed (objfile))
615 gdb_assert (debug_symfile);
616 /* Remove the current one, and reinstall a new one later. */
617 uninstall_symfile_debug_logging (objfile);
620 /* Assume debug logging is disabled. */
623 /* Turn debug logging on if enabled. */
625 install_symfile_debug_logging (objfile);
629 set_debug_symfile (char *args, int from_tty, struct cmd_list_element *c)
631 struct program_space *pspace;
632 struct objfile *objfile;
635 ALL_PSPACE_OBJFILES (pspace, objfile)
639 if (!symfile_debug_installed (objfile))
640 install_symfile_debug_logging (objfile);
644 if (symfile_debug_installed (objfile))
645 uninstall_symfile_debug_logging (objfile);
651 show_debug_symfile (struct ui_file *file, int from_tty,
652 struct cmd_list_element *c, const char *value)
654 fprintf_filtered (file, _("Symfile debugging is %s.\n"), value);
657 initialize_file_ftype _initialize_symfile_debug;
660 _initialize_symfile_debug (void)
662 symfile_debug_objfile_data_key
663 = register_objfile_data_with_cleanup (NULL, symfile_debug_free_objfile);
665 add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\
666 Set debugging of the symfile functions."), _("\
667 Show debugging of the symfile functions."), _("\
668 When enabled, all calls to the symfile functions are logged."),
669 set_debug_symfile, show_debug_symfile,
670 &setdebuglist, &showdebuglist);
672 /* Note: We don't need a new-objfile observer because debug logging
673 will be installed when objfile init'n calls objfile_set_sym_fns. */