1 /* Debug logging for the symbol file functions for the GNU debugger, GDB.
3 Copyright (C) 2013-2014 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 to return the name to print for OBJFILE. */
65 debug_objfile_name (const struct objfile
*objfile
)
67 return lbasename (objfile
->original_name
);
70 /* Utility return the name to print for SYMTAB. */
73 debug_symtab_name (struct symtab
*symtab
)
75 return symtab_to_filename_for_display (symtab
);
78 /* Debugging version of struct quick_symbol_functions. */
81 debug_qf_has_symbols (struct objfile
*objfile
)
83 const struct debug_sym_fns_data
*debug_data
=
84 objfile_data (objfile
, symfile_debug_objfile_data_key
);
87 retval
= debug_data
->real_sf
->qf
->has_symbols (objfile
);
89 fprintf_filtered (gdb_stdlog
, "qf->has_symbols (%s) = %d\n",
90 debug_objfile_name (objfile
), retval
);
95 static struct symtab
*
96 debug_qf_find_last_source_symtab (struct objfile
*objfile
)
98 const struct debug_sym_fns_data
*debug_data
=
99 objfile_data (objfile
, symfile_debug_objfile_data_key
);
100 struct symtab
*retval
;
102 fprintf_filtered (gdb_stdlog
, "qf->find_last_source_symtab (%s)\n",
103 debug_objfile_name (objfile
));
105 retval
= debug_data
->real_sf
->qf
->find_last_source_symtab (objfile
);
107 fprintf_filtered (gdb_stdlog
, "qf->find_last_source_symtab (...) = %s\n",
108 retval
? debug_symtab_name (retval
) : "NULL");
114 debug_qf_forget_cached_source_info (struct objfile
*objfile
)
116 const struct debug_sym_fns_data
*debug_data
=
117 objfile_data (objfile
, symfile_debug_objfile_data_key
);
119 fprintf_filtered (gdb_stdlog
, "qf->forget_cached_source_info (%s)\n",
120 debug_objfile_name (objfile
));
122 debug_data
->real_sf
->qf
->forget_cached_source_info (objfile
);
126 debug_qf_map_symtabs_matching_filename (struct objfile
*objfile
,
128 const char *real_path
,
129 int (*callback
) (struct symtab
*,
133 const struct debug_sym_fns_data
*debug_data
=
134 objfile_data (objfile
, symfile_debug_objfile_data_key
);
137 fprintf_filtered (gdb_stdlog
,
138 "qf->map_symtabs_matching_filename (%s, \"%s\", \"%s\", %s, %s)\n",
139 debug_objfile_name (objfile
), name
,
140 real_path
? real_path
: NULL
,
141 host_address_to_string (callback
),
142 host_address_to_string (data
));
144 retval
= debug_data
->real_sf
->qf
->map_symtabs_matching_filename
145 (objfile
, name
, real_path
, callback
, data
);
147 fprintf_filtered (gdb_stdlog
,
148 "qf->map_symtabs_matching_filename (...) = %d\n",
154 static struct symtab
*
155 debug_qf_lookup_symbol (struct objfile
*objfile
, int kind
, const char *name
,
158 const struct debug_sym_fns_data
*debug_data
=
159 objfile_data (objfile
, symfile_debug_objfile_data_key
);
160 struct symtab
*retval
;
162 fprintf_filtered (gdb_stdlog
,
163 "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
164 debug_objfile_name (objfile
), kind
, name
,
165 domain_name (domain
));
167 retval
= debug_data
->real_sf
->qf
->lookup_symbol (objfile
, kind
, name
,
170 fprintf_filtered (gdb_stdlog
, "qf->lookup_symbol (...) = %s\n",
171 retval
? debug_symtab_name (retval
) : "NULL");
177 debug_qf_print_stats (struct objfile
*objfile
)
179 const struct debug_sym_fns_data
*debug_data
=
180 objfile_data (objfile
, symfile_debug_objfile_data_key
);
182 fprintf_filtered (gdb_stdlog
, "qf->print_stats (%s)\n",
183 debug_objfile_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 objfile_data (objfile
, symfile_debug_objfile_data_key
);
194 fprintf_filtered (gdb_stdlog
, "qf->dump (%s)\n",
195 debug_objfile_name (objfile
));
197 debug_data
->real_sf
->qf
->dump (objfile
);
201 debug_qf_relocate (struct objfile
*objfile
,
202 const struct section_offsets
*new_offsets
,
203 const struct section_offsets
*delta
)
205 const struct debug_sym_fns_data
*debug_data
=
206 objfile_data (objfile
, symfile_debug_objfile_data_key
);
208 fprintf_filtered (gdb_stdlog
, "qf->relocate (%s, %s, %s)\n",
209 debug_objfile_name (objfile
),
210 host_address_to_string (new_offsets
),
211 host_address_to_string (delta
));
213 debug_data
->real_sf
->qf
->relocate (objfile
, new_offsets
, delta
);
217 debug_qf_expand_symtabs_for_function (struct objfile
*objfile
,
218 const char *func_name
)
220 const struct debug_sym_fns_data
*debug_data
=
221 objfile_data (objfile
, symfile_debug_objfile_data_key
);
223 fprintf_filtered (gdb_stdlog
,
224 "qf->expand_symtabs_for_function (%s, \"%s\")\n",
225 debug_objfile_name (objfile
), func_name
);
227 debug_data
->real_sf
->qf
->expand_symtabs_for_function (objfile
, func_name
);
231 debug_qf_expand_all_symtabs (struct objfile
*objfile
)
233 const struct debug_sym_fns_data
*debug_data
=
234 objfile_data (objfile
, symfile_debug_objfile_data_key
);
236 fprintf_filtered (gdb_stdlog
, "qf->expand_all_symtabs (%s)\n",
237 debug_objfile_name (objfile
));
239 debug_data
->real_sf
->qf
->expand_all_symtabs (objfile
);
243 debug_qf_expand_symtabs_with_fullname (struct objfile
*objfile
,
244 const char *fullname
)
246 const struct debug_sym_fns_data
*debug_data
=
247 objfile_data (objfile
, symfile_debug_objfile_data_key
);
249 fprintf_filtered (gdb_stdlog
,
250 "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
251 debug_objfile_name (objfile
), fullname
);
253 debug_data
->real_sf
->qf
->expand_symtabs_with_fullname (objfile
, fullname
);
257 debug_qf_map_matching_symbols (struct objfile
*objfile
,
258 const char *name
, domain_enum
namespace,
260 int (*callback
) (struct block
*,
261 struct symbol
*, void *),
263 symbol_compare_ftype
*match
,
264 symbol_compare_ftype
*ordered_compare
)
266 const struct debug_sym_fns_data
*debug_data
=
267 objfile_data (objfile
, symfile_debug_objfile_data_key
);
269 fprintf_filtered (gdb_stdlog
,
270 "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n",
271 debug_objfile_name (objfile
), name
,
272 domain_name (namespace), global
,
273 host_address_to_string (callback
),
274 host_address_to_string (data
),
275 host_address_to_string (match
),
276 host_address_to_string (ordered_compare
));
278 debug_data
->real_sf
->qf
->map_matching_symbols (objfile
, name
,
286 debug_qf_expand_symtabs_matching (struct objfile
*objfile
,
287 int (*file_matcher
) (const char *, void *,
289 int (*name_matcher
) (const char *, void *),
290 enum search_domain kind
,
293 const struct debug_sym_fns_data
*debug_data
=
294 objfile_data (objfile
, symfile_debug_objfile_data_key
);
296 fprintf_filtered (gdb_stdlog
,
297 "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
298 debug_objfile_name (objfile
),
299 host_address_to_string (file_matcher
),
300 host_address_to_string (name_matcher
),
301 search_domain_name (kind
),
302 host_address_to_string (data
));
304 debug_data
->real_sf
->qf
->expand_symtabs_matching (objfile
,
310 static struct symtab
*
311 debug_qf_find_pc_sect_symtab (struct objfile
*objfile
,
312 struct minimal_symbol
*msymbol
,
314 struct obj_section
*section
,
317 const struct debug_sym_fns_data
*debug_data
=
318 objfile_data (objfile
, symfile_debug_objfile_data_key
);
319 struct symtab
*retval
;
321 fprintf_filtered (gdb_stdlog
,
322 "qf->find_pc_sect_symtab (%s, %s, %s, %s, %d)\n",
323 debug_objfile_name (objfile
),
324 host_address_to_string (msymbol
),
326 host_address_to_string (section
),
329 retval
= debug_data
->real_sf
->qf
->find_pc_sect_symtab (objfile
, msymbol
,
333 fprintf_filtered (gdb_stdlog
, "qf->find_pc_sect_symtab (...) = %s\n",
334 retval
? debug_symtab_name (retval
) : "NULL");
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 debug_objfile_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_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 debug_objfile_name (objfile
),
390 host_address_to_string (retval
));
396 debug_sym_relocate_probe (struct objfile
*objfile
,
397 const struct section_offsets
*new_offsets
,
398 const struct section_offsets
*delta
)
400 const struct debug_sym_fns_data
*debug_data
=
401 objfile_data (objfile
, symfile_debug_objfile_data_key
);
403 fprintf_filtered (gdb_stdlog
,
404 "probes->sym_relocate_probe (%s, %s, %s)\n",
405 debug_objfile_name (objfile
),
406 host_address_to_string (new_offsets
),
407 host_address_to_string (delta
));
409 debug_data
->real_sf
->sym_probe_fns
->sym_relocate_probe
410 (objfile
, new_offsets
, delta
);
413 static const struct sym_probe_fns debug_sym_probe_fns
=
415 debug_sym_get_probes
,
416 debug_sym_relocate_probe
419 /* Debugging version of struct sym_fns. */
422 debug_sym_new_init (struct objfile
*objfile
)
424 const struct debug_sym_fns_data
*debug_data
=
425 objfile_data (objfile
, symfile_debug_objfile_data_key
);
427 fprintf_filtered (gdb_stdlog
, "sf->sym_new_init (%s)\n",
428 debug_objfile_name (objfile
));
430 debug_data
->real_sf
->sym_new_init (objfile
);
434 debug_sym_init (struct objfile
*objfile
)
436 const struct debug_sym_fns_data
*debug_data
=
437 objfile_data (objfile
, symfile_debug_objfile_data_key
);
439 fprintf_filtered (gdb_stdlog
, "sf->sym_init (%s)\n",
440 debug_objfile_name (objfile
));
442 debug_data
->real_sf
->sym_init (objfile
);
446 debug_sym_read (struct objfile
*objfile
, int symfile_flags
)
448 const struct debug_sym_fns_data
*debug_data
=
449 objfile_data (objfile
, symfile_debug_objfile_data_key
);
451 fprintf_filtered (gdb_stdlog
, "sf->sym_read (%s, 0x%x)\n",
452 debug_objfile_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 objfile_data (objfile
, symfile_debug_objfile_data_key
);
463 fprintf_filtered (gdb_stdlog
, "sf->sym_read_psymbols (%s)\n",
464 debug_objfile_name (objfile
));
466 debug_data
->real_sf
->sym_read_psymbols (objfile
);
470 debug_sym_finish (struct objfile
*objfile
)
472 const struct debug_sym_fns_data
*debug_data
=
473 objfile_data (objfile
, symfile_debug_objfile_data_key
);
475 fprintf_filtered (gdb_stdlog
, "sf->sym_finish (%s)\n",
476 debug_objfile_name (objfile
));
478 debug_data
->real_sf
->sym_finish (objfile
);
482 debug_sym_offsets (struct objfile
*objfile
,
483 const struct section_addr_info
*info
)
485 const struct debug_sym_fns_data
*debug_data
=
486 objfile_data (objfile
, symfile_debug_objfile_data_key
);
488 fprintf_filtered (gdb_stdlog
, "sf->sym_offsets (%s, %s)\n",
489 debug_objfile_name (objfile
),
490 host_address_to_string (info
));
492 debug_data
->real_sf
->sym_offsets (objfile
, info
);
495 static struct symfile_segment_data
*
496 debug_sym_segments (bfd
*abfd
)
498 /* This API function is annoying, it doesn't take a "this" pointer.
499 Fortunately it is only used in one place where we (re-)lookup the
500 sym_fns table to use. Thus we will never be called. */
501 gdb_assert_not_reached ("debug_sym_segments called");
505 debug_sym_read_linetable (struct objfile
*objfile
)
507 const struct debug_sym_fns_data
*debug_data
=
508 objfile_data (objfile
, symfile_debug_objfile_data_key
);
510 fprintf_filtered (gdb_stdlog
, "sf->sym_read_linetable (%s)\n",
511 debug_objfile_name (objfile
));
513 debug_data
->real_sf
->sym_read_linetable (objfile
);
517 debug_sym_relocate (struct objfile
*objfile
, asection
*sectp
, bfd_byte
*buf
)
519 const struct debug_sym_fns_data
*debug_data
=
520 objfile_data (objfile
, symfile_debug_objfile_data_key
);
523 retval
= debug_data
->real_sf
->sym_relocate (objfile
, sectp
, buf
);
525 fprintf_filtered (gdb_stdlog
,
526 "sf->sym_relocate (%s, %s, %s) = %s\n",
527 debug_objfile_name (objfile
),
528 host_address_to_string (sectp
),
529 host_address_to_string (buf
),
530 host_address_to_string (retval
));
535 /* Template of debugging version of struct sym_fns.
536 A copy is made, with sym_flavour updated, and a pointer to the real table
537 installed in real_sf, and then a pointer to the copy is installed in the
540 static const struct sym_fns debug_sym_fns
=
545 debug_sym_read_psymbols
,
549 debug_sym_read_linetable
,
551 &debug_sym_probe_fns
,
552 &debug_sym_quick_functions
555 /* Free the copy of sym_fns recorded in the registry. */
558 symfile_debug_free_objfile (struct objfile
*objfile
, void *datum
)
563 /* Install the debugging versions of the symfile functions for OBJFILE.
564 Do not call this if the debug versions are already installed. */
567 install_symfile_debug_logging (struct objfile
*objfile
)
569 const struct sym_fns
*real_sf
;
570 struct debug_sym_fns_data
*debug_data
;
572 /* The debug versions should not already be installed. */
573 gdb_assert (!symfile_debug_installed (objfile
));
575 real_sf
= objfile
->sf
;
577 /* Alas we have to preserve NULL entries in REAL_SF. */
578 debug_data
= XZALLOC (struct debug_sym_fns_data
);
580 #define COPY_SF_PTR(from, to, name, func) \
583 (to)->debug_sf.name = func; \
586 COPY_SF_PTR (real_sf
, debug_data
, sym_new_init
, debug_sym_new_init
);
587 COPY_SF_PTR (real_sf
, debug_data
, sym_init
, debug_sym_init
);
588 COPY_SF_PTR (real_sf
, debug_data
, sym_read
, debug_sym_read
);
589 COPY_SF_PTR (real_sf
, debug_data
, sym_read_psymbols
,
590 debug_sym_read_psymbols
);
591 COPY_SF_PTR (real_sf
, debug_data
, sym_finish
, debug_sym_finish
);
592 COPY_SF_PTR (real_sf
, debug_data
, sym_offsets
, debug_sym_offsets
);
593 COPY_SF_PTR (real_sf
, debug_data
, sym_segments
, debug_sym_segments
);
594 COPY_SF_PTR (real_sf
, debug_data
, sym_read_linetable
,
595 debug_sym_read_linetable
);
596 COPY_SF_PTR (real_sf
, debug_data
, sym_relocate
, debug_sym_relocate
);
597 if (real_sf
->sym_probe_fns
)
598 debug_data
->debug_sf
.sym_probe_fns
= &debug_sym_probe_fns
;
599 debug_data
->debug_sf
.qf
= &debug_sym_quick_functions
;
603 debug_data
->real_sf
= real_sf
;
604 set_objfile_data (objfile
, symfile_debug_objfile_data_key
, debug_data
);
605 objfile
->sf
= &debug_data
->debug_sf
;
608 /* Uninstall the debugging versions of the symfile functions for OBJFILE.
609 Do not call this if the debug versions are not installed. */
612 uninstall_symfile_debug_logging (struct objfile
*objfile
)
614 struct debug_sym_fns_data
*debug_data
;
616 /* The debug versions should be currently installed. */
617 gdb_assert (symfile_debug_installed (objfile
));
619 debug_data
= objfile_data (objfile
, symfile_debug_objfile_data_key
);
621 objfile
->sf
= debug_data
->real_sf
;
623 set_objfile_data (objfile
, symfile_debug_objfile_data_key
, NULL
);
626 /* Call this function to set OBJFILE->SF.
627 Do not set OBJFILE->SF directly. */
630 objfile_set_sym_fns (struct objfile
*objfile
, const struct sym_fns
*sf
)
632 if (symfile_debug_installed (objfile
))
634 gdb_assert (debug_symfile
);
635 /* Remove the current one, and reinstall a new one later. */
636 uninstall_symfile_debug_logging (objfile
);
639 /* Assume debug logging is disabled. */
642 /* Turn debug logging on if enabled. */
644 install_symfile_debug_logging (objfile
);
648 set_debug_symfile (char *args
, int from_tty
, struct cmd_list_element
*c
)
650 struct program_space
*pspace
;
651 struct objfile
*objfile
;
654 ALL_PSPACE_OBJFILES (pspace
, objfile
)
658 if (!symfile_debug_installed (objfile
))
659 install_symfile_debug_logging (objfile
);
663 if (symfile_debug_installed (objfile
))
664 uninstall_symfile_debug_logging (objfile
);
670 show_debug_symfile (struct ui_file
*file
, int from_tty
,
671 struct cmd_list_element
*c
, const char *value
)
673 fprintf_filtered (file
, _("Symfile debugging is %s.\n"), value
);
676 initialize_file_ftype _initialize_symfile_debug
;
679 _initialize_symfile_debug (void)
681 symfile_debug_objfile_data_key
682 = register_objfile_data_with_cleanup (NULL
, symfile_debug_free_objfile
);
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
);
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. */