1 /* Debug logging for the symbol file functions for the GNU debugger, GDB.
3 Copyright (C) 2013-2016 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 = ((const struct debug_sym_fns_data *)
77 objfile_data (objfile, symfile_debug_objfile_data_key));
80 retval = debug_data->real_sf->qf->has_symbols (objfile);
82 fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n",
83 objfile_debug_name (objfile), retval);
88 static struct symtab *
89 debug_qf_find_last_source_symtab (struct objfile *objfile)
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));
94 struct symtab *retval;
96 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
97 objfile_debug_name (objfile));
99 retval = debug_data->real_sf->qf->find_last_source_symtab (objfile);
101 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n",
102 retval ? debug_symtab_name (retval) : "NULL");
108 debug_qf_forget_cached_source_info (struct objfile *objfile)
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));
114 fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
115 objfile_debug_name (objfile));
117 debug_data->real_sf->qf->forget_cached_source_info (objfile);
121 debug_qf_map_symtabs_matching_filename (struct objfile *objfile,
123 const char *real_path,
124 int (*callback) (struct symtab *,
128 const struct debug_sym_fns_data *debug_data
129 = ((const struct debug_sym_fns_data *)
130 objfile_data (objfile, symfile_debug_objfile_data_key));
133 fprintf_filtered (gdb_stdlog,
134 "qf->map_symtabs_matching_filename (%s, \"%s\", \"%s\", %s, %s)\n",
135 objfile_debug_name (objfile), name,
136 real_path ? real_path : NULL,
137 host_address_to_string (callback),
138 host_address_to_string (data));
140 retval = debug_data->real_sf->qf->map_symtabs_matching_filename
141 (objfile, name, real_path, callback, data);
143 fprintf_filtered (gdb_stdlog,
144 "qf->map_symtabs_matching_filename (...) = %d\n",
150 static struct compunit_symtab *
151 debug_qf_lookup_symbol (struct objfile *objfile, int kind, const char *name,
154 const struct debug_sym_fns_data *debug_data
155 = ((const struct debug_sym_fns_data *)
156 objfile_data (objfile, symfile_debug_objfile_data_key));
157 struct compunit_symtab *retval;
159 fprintf_filtered (gdb_stdlog,
160 "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
161 objfile_debug_name (objfile), kind, name,
162 domain_name (domain));
164 retval = debug_data->real_sf->qf->lookup_symbol (objfile, kind, name,
167 fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
169 ? debug_symtab_name (compunit_primary_filetab (retval))
176 debug_qf_print_stats (struct objfile *objfile)
178 const struct debug_sym_fns_data *debug_data
179 = ((const struct debug_sym_fns_data *)
180 objfile_data (objfile, symfile_debug_objfile_data_key));
182 fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
183 objfile_debug_name (objfile));
185 debug_data->real_sf->qf->print_stats (objfile);
189 debug_qf_dump (struct objfile *objfile)
191 const struct debug_sym_fns_data *debug_data
192 = ((const struct debug_sym_fns_data *)
193 objfile_data (objfile, symfile_debug_objfile_data_key));
195 fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
196 objfile_debug_name (objfile));
198 debug_data->real_sf->qf->dump (objfile);
202 debug_qf_relocate (struct objfile *objfile,
203 const struct section_offsets *new_offsets,
204 const struct section_offsets *delta)
206 const struct debug_sym_fns_data *debug_data
207 = ((const struct debug_sym_fns_data *)
208 objfile_data (objfile, symfile_debug_objfile_data_key));
210 fprintf_filtered (gdb_stdlog, "qf->relocate (%s, %s, %s)\n",
211 objfile_debug_name (objfile),
212 host_address_to_string (new_offsets),
213 host_address_to_string (delta));
215 debug_data->real_sf->qf->relocate (objfile, new_offsets, delta);
219 debug_qf_expand_symtabs_for_function (struct objfile *objfile,
220 const char *func_name)
222 const struct debug_sym_fns_data *debug_data
223 = ((const struct debug_sym_fns_data *)
224 objfile_data (objfile, symfile_debug_objfile_data_key));
226 fprintf_filtered (gdb_stdlog,
227 "qf->expand_symtabs_for_function (%s, \"%s\")\n",
228 objfile_debug_name (objfile), func_name);
230 debug_data->real_sf->qf->expand_symtabs_for_function (objfile, func_name);
234 debug_qf_expand_all_symtabs (struct objfile *objfile)
236 const struct debug_sym_fns_data *debug_data
237 = ((const struct debug_sym_fns_data *)
238 objfile_data (objfile, symfile_debug_objfile_data_key));
240 fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
241 objfile_debug_name (objfile));
243 debug_data->real_sf->qf->expand_all_symtabs (objfile);
247 debug_qf_expand_symtabs_with_fullname (struct objfile *objfile,
248 const char *fullname)
250 const struct debug_sym_fns_data *debug_data
251 = ((const struct debug_sym_fns_data *)
252 objfile_data (objfile, symfile_debug_objfile_data_key));
254 fprintf_filtered (gdb_stdlog,
255 "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
256 objfile_debug_name (objfile), fullname);
258 debug_data->real_sf->qf->expand_symtabs_with_fullname (objfile, fullname);
262 debug_qf_map_matching_symbols (struct objfile *objfile,
263 const char *name, domain_enum domain,
265 int (*callback) (struct block *,
266 struct symbol *, void *),
268 symbol_compare_ftype *match,
269 symbol_compare_ftype *ordered_compare)
271 const struct debug_sym_fns_data *debug_data
272 = ((const struct debug_sym_fns_data *)
273 objfile_data (objfile, symfile_debug_objfile_data_key));
275 fprintf_filtered (gdb_stdlog,
276 "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n",
277 objfile_debug_name (objfile), name,
278 domain_name (domain), global,
279 host_address_to_string (callback),
280 host_address_to_string (data),
281 host_address_to_string (match),
282 host_address_to_string (ordered_compare));
284 debug_data->real_sf->qf->map_matching_symbols (objfile, name,
292 debug_qf_expand_symtabs_matching
293 (struct objfile *objfile,
294 expand_symtabs_file_matcher_ftype *file_matcher,
295 expand_symtabs_symbol_matcher_ftype *symbol_matcher,
296 expand_symtabs_exp_notify_ftype *expansion_notify,
297 enum search_domain kind, void *data)
299 const struct debug_sym_fns_data *debug_data
300 = ((const struct debug_sym_fns_data *)
301 objfile_data (objfile, symfile_debug_objfile_data_key));
303 fprintf_filtered (gdb_stdlog,
304 "qf->expand_symtabs_matching (%s, %s, %s, %s, %s, %s)\n",
305 objfile_debug_name (objfile),
306 host_address_to_string (file_matcher),
307 host_address_to_string (symbol_matcher),
308 host_address_to_string (expansion_notify),
309 search_domain_name (kind),
310 host_address_to_string (data));
312 debug_data->real_sf->qf->expand_symtabs_matching (objfile,
319 static struct compunit_symtab *
320 debug_qf_find_pc_sect_compunit_symtab (struct objfile *objfile,
321 struct bound_minimal_symbol msymbol,
323 struct obj_section *section,
326 const struct debug_sym_fns_data *debug_data
327 = ((const struct debug_sym_fns_data *)
328 objfile_data (objfile, symfile_debug_objfile_data_key));
329 struct compunit_symtab *retval;
331 fprintf_filtered (gdb_stdlog,
332 "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n",
333 objfile_debug_name (objfile),
334 host_address_to_string (msymbol.minsym),
336 host_address_to_string (section),
340 = debug_data->real_sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol,
344 fprintf_filtered (gdb_stdlog,
345 "qf->find_pc_sect_compunit_symtab (...) = %s\n",
347 ? debug_symtab_name (compunit_primary_filetab (retval))
354 debug_qf_map_symbol_filenames (struct objfile *objfile,
355 symbol_filename_ftype *fun, void *data,
358 const struct debug_sym_fns_data *debug_data
359 = ((const struct debug_sym_fns_data *)
360 objfile_data (objfile, symfile_debug_objfile_data_key));
361 fprintf_filtered (gdb_stdlog,
362 "qf->map_symbol_filenames (%s, %s, %s, %d)\n",
363 objfile_debug_name (objfile),
364 host_address_to_string (fun),
365 host_address_to_string (data),
368 debug_data->real_sf->qf->map_symbol_filenames (objfile, fun, data,
372 static const struct quick_symbol_functions debug_sym_quick_functions =
374 debug_qf_has_symbols,
375 debug_qf_find_last_source_symtab,
376 debug_qf_forget_cached_source_info,
377 debug_qf_map_symtabs_matching_filename,
378 debug_qf_lookup_symbol,
379 debug_qf_print_stats,
382 debug_qf_expand_symtabs_for_function,
383 debug_qf_expand_all_symtabs,
384 debug_qf_expand_symtabs_with_fullname,
385 debug_qf_map_matching_symbols,
386 debug_qf_expand_symtabs_matching,
387 debug_qf_find_pc_sect_compunit_symtab,
388 debug_qf_map_symbol_filenames
391 /* Debugging version of struct sym_probe_fns. */
393 static VEC (probe_p) *
394 debug_sym_get_probes (struct objfile *objfile)
396 const struct debug_sym_fns_data *debug_data
397 = ((const struct debug_sym_fns_data *)
398 objfile_data (objfile, symfile_debug_objfile_data_key));
399 VEC (probe_p) *retval;
401 retval = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile);
403 fprintf_filtered (gdb_stdlog,
404 "probes->sym_get_probes (%s) = %s\n",
405 objfile_debug_name (objfile),
406 host_address_to_string (retval));
411 static const struct sym_probe_fns debug_sym_probe_fns =
413 debug_sym_get_probes,
416 /* Debugging version of struct sym_fns. */
419 debug_sym_new_init (struct objfile *objfile)
421 const struct debug_sym_fns_data *debug_data
422 = ((const struct debug_sym_fns_data *)
423 objfile_data (objfile, symfile_debug_objfile_data_key));
425 fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n",
426 objfile_debug_name (objfile));
428 debug_data->real_sf->sym_new_init (objfile);
432 debug_sym_init (struct objfile *objfile)
434 const struct debug_sym_fns_data *debug_data
435 = ((const struct debug_sym_fns_data *)
436 objfile_data (objfile, symfile_debug_objfile_data_key));
438 fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n",
439 objfile_debug_name (objfile));
441 debug_data->real_sf->sym_init (objfile);
445 debug_sym_read (struct objfile *objfile, int symfile_flags)
447 const struct debug_sym_fns_data *debug_data
448 = ((const struct debug_sym_fns_data *)
449 objfile_data (objfile, symfile_debug_objfile_data_key));
451 fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n",
452 objfile_debug_name (objfile), symfile_flags);
454 debug_data->real_sf->sym_read (objfile, symfile_flags);
458 debug_sym_read_psymbols (struct objfile *objfile)
460 const struct debug_sym_fns_data *debug_data
461 = ((const struct debug_sym_fns_data *)
462 objfile_data (objfile, symfile_debug_objfile_data_key));
464 fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n",
465 objfile_debug_name (objfile));
467 debug_data->real_sf->sym_read_psymbols (objfile);
471 debug_sym_finish (struct objfile *objfile)
473 const struct debug_sym_fns_data *debug_data
474 = ((const struct debug_sym_fns_data *)
475 objfile_data (objfile, symfile_debug_objfile_data_key));
477 fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n",
478 objfile_debug_name (objfile));
480 debug_data->real_sf->sym_finish (objfile);
484 debug_sym_offsets (struct objfile *objfile,
485 const struct section_addr_info *info)
487 const struct debug_sym_fns_data *debug_data
488 = ((const struct debug_sym_fns_data *)
489 objfile_data (objfile, symfile_debug_objfile_data_key));
491 fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n",
492 objfile_debug_name (objfile),
493 host_address_to_string (info));
495 debug_data->real_sf->sym_offsets (objfile, info);
498 static struct symfile_segment_data *
499 debug_sym_segments (bfd *abfd)
501 /* This API function is annoying, it doesn't take a "this" pointer.
502 Fortunately it is only used in one place where we (re-)lookup the
503 sym_fns table to use. Thus we will never be called. */
504 gdb_assert_not_reached ("debug_sym_segments called");
508 debug_sym_read_linetable (struct objfile *objfile)
510 const struct debug_sym_fns_data *debug_data
511 = ((const struct debug_sym_fns_data *)
512 objfile_data (objfile, symfile_debug_objfile_data_key));
514 fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n",
515 objfile_debug_name (objfile));
517 debug_data->real_sf->sym_read_linetable (objfile);
521 debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf)
523 const struct debug_sym_fns_data *debug_data
524 = ((const struct debug_sym_fns_data *)
525 objfile_data (objfile, symfile_debug_objfile_data_key));
528 retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf);
530 fprintf_filtered (gdb_stdlog,
531 "sf->sym_relocate (%s, %s, %s) = %s\n",
532 objfile_debug_name (objfile),
533 host_address_to_string (sectp),
534 host_address_to_string (buf),
535 host_address_to_string (retval));
540 /* Template of debugging version of struct sym_fns.
541 A copy is made, with sym_flavour updated, and a pointer to the real table
542 installed in real_sf, and then a pointer to the copy is installed in the
545 static const struct sym_fns debug_sym_fns =
550 debug_sym_read_psymbols,
554 debug_sym_read_linetable,
556 &debug_sym_probe_fns,
557 &debug_sym_quick_functions
560 /* Free the copy of sym_fns recorded in the registry. */
563 symfile_debug_free_objfile (struct objfile *objfile, void *datum)
568 /* Install the debugging versions of the symfile functions for OBJFILE.
569 Do not call this if the debug versions are already installed. */
572 install_symfile_debug_logging (struct objfile *objfile)
574 const struct sym_fns *real_sf;
575 struct debug_sym_fns_data *debug_data;
577 /* The debug versions should not already be installed. */
578 gdb_assert (!symfile_debug_installed (objfile));
580 real_sf = objfile->sf;
582 /* Alas we have to preserve NULL entries in REAL_SF. */
583 debug_data = XCNEW (struct debug_sym_fns_data);
585 #define COPY_SF_PTR(from, to, name, func) \
588 (to)->debug_sf.name = func; \
591 COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init);
592 COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init);
593 COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read);
594 COPY_SF_PTR (real_sf, debug_data, sym_read_psymbols,
595 debug_sym_read_psymbols);
596 COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish);
597 COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets);
598 COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments);
599 COPY_SF_PTR (real_sf, debug_data, sym_read_linetable,
600 debug_sym_read_linetable);
601 COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate);
602 if (real_sf->sym_probe_fns)
603 debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns;
604 debug_data->debug_sf.qf = &debug_sym_quick_functions;
608 debug_data->real_sf = real_sf;
609 set_objfile_data (objfile, symfile_debug_objfile_data_key, debug_data);
610 objfile->sf = &debug_data->debug_sf;
613 /* Uninstall the debugging versions of the symfile functions for OBJFILE.
614 Do not call this if the debug versions are not installed. */
617 uninstall_symfile_debug_logging (struct objfile *objfile)
619 struct debug_sym_fns_data *debug_data;
621 /* The debug versions should be currently installed. */
622 gdb_assert (symfile_debug_installed (objfile));
624 debug_data = ((struct debug_sym_fns_data *)
625 objfile_data (objfile, symfile_debug_objfile_data_key));
627 objfile->sf = debug_data->real_sf;
629 set_objfile_data (objfile, symfile_debug_objfile_data_key, NULL);
632 /* Call this function to set OBJFILE->SF.
633 Do not set OBJFILE->SF directly. */
636 objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf)
638 if (symfile_debug_installed (objfile))
640 gdb_assert (debug_symfile);
641 /* Remove the current one, and reinstall a new one later. */
642 uninstall_symfile_debug_logging (objfile);
645 /* Assume debug logging is disabled. */
648 /* Turn debug logging on if enabled. */
650 install_symfile_debug_logging (objfile);
654 set_debug_symfile (char *args, int from_tty, struct cmd_list_element *c)
656 struct program_space *pspace;
657 struct objfile *objfile;
660 ALL_PSPACE_OBJFILES (pspace, objfile)
664 if (!symfile_debug_installed (objfile))
665 install_symfile_debug_logging (objfile);
669 if (symfile_debug_installed (objfile))
670 uninstall_symfile_debug_logging (objfile);
676 show_debug_symfile (struct ui_file *file, int from_tty,
677 struct cmd_list_element *c, const char *value)
679 fprintf_filtered (file, _("Symfile debugging is %s.\n"), value);
682 initialize_file_ftype _initialize_symfile_debug;
685 _initialize_symfile_debug (void)
687 symfile_debug_objfile_data_key
688 = register_objfile_data_with_cleanup (NULL, symfile_debug_free_objfile);
690 add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\
691 Set debugging of the symfile functions."), _("\
692 Show debugging of the symfile functions."), _("\
693 When enabled, all calls to the symfile functions are logged."),
694 set_debug_symfile, show_debug_symfile,
695 &setdebuglist, &showdebuglist);
697 /* Note: We don't need a new-objfile observer because debug logging
698 will be installed when objfile init'n calls objfile_set_sym_fns. */