1 /* Debug logging for the symbol file functions for the GNU debugger, GDB.
3 Copyright (C) 2013-2023 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
31 #include "observable.h"
36 #include "filenames.h"
37 #include "cli/cli-style.h"
39 #include "debuginfod-support.h"
41 /* We need to save a pointer to the real symbol functions.
42 Plus, the debug versions are malloc'd because we have to NULL out the
43 ones that are NULL in the real copy. */
45 struct debug_sym_fns_data
47 const struct sym_fns
*real_sf
= nullptr;
48 struct sym_fns debug_sf
{};
51 /* We need to record a pointer to the real set of functions for each
53 static const registry
<objfile
>::key
<debug_sym_fns_data
>
54 symfile_debug_objfile_data_key
;
56 /* If true all calls to the symfile functions are logged. */
57 static bool debug_symfile
= false;
59 /* Return non-zero if symfile debug logging is installed. */
62 symfile_debug_installed (struct objfile
*objfile
)
64 return (objfile
->sf
!= NULL
65 && symfile_debug_objfile_data_key
.get (objfile
) != NULL
);
68 /* Utility return the name to print for SYMTAB. */
71 debug_symtab_name (struct symtab
*symtab
)
73 return symtab_to_filename_for_display (symtab
);
80 objfile::has_partial_symbols ()
84 /* If we have not read psymbols, but we have a function capable of reading
85 them, then that is an indication that they are in fact available. Without
86 this function the symbols may have been already read in but they also may
87 not be present in this objfile. */
88 for (const auto &iter
: qf
)
90 if ((flags
& OBJF_PSYMTABS_READ
) == 0
91 && iter
->can_lazily_read_symbols ())
94 retval
= iter
->has_symbols (this);
100 gdb_printf (gdb_stdlog
, "qf->has_symbols (%s) = %d\n",
101 objfile_debug_name (this), retval
);
106 /* See objfiles.h. */
108 objfile::has_unexpanded_symtabs ()
111 gdb_printf (gdb_stdlog
, "qf->has_unexpanded_symtabs (%s)\n",
112 objfile_debug_name (this));
115 for (const auto &iter
: qf_require_partial_symbols ())
117 if (iter
->has_unexpanded_symtabs (this))
125 gdb_printf (gdb_stdlog
, "qf->has_unexpanded_symtabs (%s) = %d\n",
126 objfile_debug_name (this), (result
? 1 : 0));
132 objfile::find_last_source_symtab ()
134 struct symtab
*retval
= nullptr;
137 gdb_printf (gdb_stdlog
, "qf->find_last_source_symtab (%s)\n",
138 objfile_debug_name (this));
140 for (const auto &iter
: qf_require_partial_symbols ())
142 retval
= iter
->find_last_source_symtab (this);
143 if (retval
!= nullptr)
148 gdb_printf (gdb_stdlog
, "qf->find_last_source_symtab (...) = %s\n",
149 retval
? debug_symtab_name (retval
) : "NULL");
155 objfile::forget_cached_source_info ()
158 gdb_printf (gdb_stdlog
, "qf->forget_cached_source_info (%s)\n",
159 objfile_debug_name (this));
161 for (compunit_symtab
*cu
: compunits ())
163 for (symtab
*s
: cu
->filetabs ())
165 if (s
->fullname
!= NULL
)
173 for (const auto &iter
: qf_require_partial_symbols ())
174 iter
->forget_cached_source_info (this);
178 objfile::map_symtabs_matching_filename
179 (const char *name
, const char *real_path
,
180 gdb::function_view
<bool (symtab
*)> callback
)
183 gdb_printf (gdb_stdlog
,
184 "qf->map_symtabs_matching_filename (%s, \"%s\", "
186 objfile_debug_name (this), name
,
187 real_path
? real_path
: NULL
,
188 host_address_to_string (&callback
));
191 const char *name_basename
= lbasename (name
);
193 auto match_one_filename
= [&] (const char *filename
, bool basenames
)
195 if (compare_filenames_for_search (filename
, name
))
197 if (basenames
&& FILENAME_CMP (name_basename
, filename
) == 0)
199 if (real_path
!= nullptr && IS_ABSOLUTE_PATH (filename
)
200 && IS_ABSOLUTE_PATH (real_path
))
201 return filename_cmp (filename
, real_path
) == 0;
205 compunit_symtab
*last_made
= this->compunit_symtabs
;
207 auto on_expansion
= [&] (compunit_symtab
*symtab
)
209 /* The callback to iterate_over_some_symtabs returns false to keep
210 going and true to continue, so we have to invert the result
211 here, for expand_symtabs_matching. */
212 bool result
= !iterate_over_some_symtabs (name
, real_path
,
213 this->compunit_symtabs
,
216 last_made
= this->compunit_symtabs
;
220 for (const auto &iter
: qf_require_partial_symbols ())
222 if (!iter
->expand_symtabs_matching (this,
228 | SEARCH_STATIC_BLOCK
),
238 gdb_printf (gdb_stdlog
,
239 "qf->map_symtabs_matching_filename (...) = %d\n",
242 /* We must re-invert the return value here to match the caller's
247 struct compunit_symtab
*
248 objfile::lookup_symbol (block_enum kind
, const char *name
, domain_enum domain
)
250 struct compunit_symtab
*retval
= nullptr;
253 gdb_printf (gdb_stdlog
,
254 "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
255 objfile_debug_name (this), kind
, name
,
256 domain_name (domain
));
258 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
260 auto search_one_symtab
= [&] (compunit_symtab
*stab
)
262 struct symbol
*sym
, *with_opaque
= NULL
;
263 const struct blockvector
*bv
= stab
->blockvector ();
264 const struct block
*block
= bv
->block (kind
);
266 sym
= block_find_symbol (block
, lookup_name
, domain
, &with_opaque
);
268 /* Some caution must be observed with overloaded functions
269 and methods, since the index will not contain any overload
270 information (but NAME might contain it). */
278 if (with_opaque
!= nullptr)
281 /* Keep looking through other psymtabs. */
285 for (const auto &iter
: qf_require_partial_symbols ())
287 if (!iter
->expand_symtabs_matching (this,
293 ? SEARCH_GLOBAL_BLOCK
294 : SEARCH_STATIC_BLOCK
,
301 gdb_printf (gdb_stdlog
, "qf->lookup_symbol (...) = %s\n",
303 ? debug_symtab_name (retval
->primary_filetab ())
310 objfile::print_stats (bool print_bcache
)
313 gdb_printf (gdb_stdlog
, "qf->print_stats (%s, %d)\n",
314 objfile_debug_name (this), print_bcache
);
316 for (const auto &iter
: qf_require_partial_symbols ())
317 iter
->print_stats (this, print_bcache
);
324 gdb_printf (gdb_stdlog
, "qf->dump (%s)\n",
325 objfile_debug_name (this));
327 for (const auto &iter
: qf
)
332 objfile::expand_symtabs_for_function (const char *func_name
)
335 gdb_printf (gdb_stdlog
,
336 "qf->expand_symtabs_for_function (%s, \"%s\")\n",
337 objfile_debug_name (this), func_name
);
339 lookup_name_info
base_lookup (func_name
, symbol_name_match_type::FULL
);
340 lookup_name_info lookup_name
= base_lookup
.make_ignore_params ();
342 for (const auto &iter
: qf_require_partial_symbols ())
343 iter
->expand_symtabs_matching (this,
349 | SEARCH_STATIC_BLOCK
),
355 objfile::expand_all_symtabs ()
358 gdb_printf (gdb_stdlog
, "qf->expand_all_symtabs (%s)\n",
359 objfile_debug_name (this));
361 for (const auto &iter
: qf_require_partial_symbols ())
362 iter
->expand_all_symtabs (this);
366 objfile::expand_symtabs_with_fullname (const char *fullname
)
369 gdb_printf (gdb_stdlog
,
370 "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
371 objfile_debug_name (this), fullname
);
373 const char *basename
= lbasename (fullname
);
374 auto file_matcher
= [&] (const char *filename
, bool basenames
)
376 return filename_cmp (basenames
? basename
: fullname
, filename
) == 0;
379 for (const auto &iter
: qf_require_partial_symbols ())
380 iter
->expand_symtabs_matching (this,
386 | SEARCH_STATIC_BLOCK
),
392 objfile::expand_matching_symbols
393 (const lookup_name_info
&name
, domain_enum domain
,
395 symbol_compare_ftype
*ordered_compare
)
398 gdb_printf (gdb_stdlog
,
399 "qf->expand_matching_symbols (%s, %s, %d, %s)\n",
400 objfile_debug_name (this),
401 domain_name (domain
), global
,
402 host_address_to_string (ordered_compare
));
404 for (const auto &iter
: qf_require_partial_symbols ())
405 iter
->expand_matching_symbols (this, name
, domain
, global
,
410 objfile::expand_symtabs_matching
411 (gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
412 const lookup_name_info
*lookup_name
,
413 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
414 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
415 block_search_flags search_flags
,
417 enum search_domain kind
)
419 /* This invariant is documented in quick-functions.h. */
420 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
423 gdb_printf (gdb_stdlog
,
424 "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
425 objfile_debug_name (this),
426 host_address_to_string (&file_matcher
),
427 host_address_to_string (&symbol_matcher
),
428 host_address_to_string (&expansion_notify
),
429 search_domain_name (kind
));
431 for (const auto &iter
: qf_require_partial_symbols ())
432 if (!iter
->expand_symtabs_matching (this, file_matcher
, lookup_name
,
433 symbol_matcher
, expansion_notify
,
434 search_flags
, domain
, kind
))
439 struct compunit_symtab
*
440 objfile::find_pc_sect_compunit_symtab (struct bound_minimal_symbol msymbol
,
442 struct obj_section
*section
,
445 struct compunit_symtab
*retval
= nullptr;
448 gdb_printf (gdb_stdlog
,
449 "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n",
450 objfile_debug_name (this),
451 host_address_to_string (msymbol
.minsym
),
453 host_address_to_string (section
),
456 for (const auto &iter
: qf_require_partial_symbols ())
458 retval
= iter
->find_pc_sect_compunit_symtab (this, msymbol
, pc
, section
,
460 if (retval
!= nullptr)
465 gdb_printf (gdb_stdlog
,
466 "qf->find_pc_sect_compunit_symtab (...) = %s\n",
468 ? debug_symtab_name (retval
->primary_filetab ())
475 objfile::map_symbol_filenames (gdb::function_view
<symbol_filename_ftype
> fun
,
479 gdb_printf (gdb_stdlog
,
480 "qf->map_symbol_filenames (%s, ..., %d)\n",
481 objfile_debug_name (this),
484 for (const auto &iter
: qf_require_partial_symbols ())
485 iter
->map_symbol_filenames (this, fun
, need_fullname
);
488 struct compunit_symtab
*
489 objfile::find_compunit_symtab_by_address (CORE_ADDR address
)
492 gdb_printf (gdb_stdlog
,
493 "qf->find_compunit_symtab_by_address (%s, %s)\n",
494 objfile_debug_name (this),
495 hex_string (address
));
497 struct compunit_symtab
*result
= NULL
;
498 for (const auto &iter
: qf_require_partial_symbols ())
500 result
= iter
->find_compunit_symtab_by_address (this, address
);
501 if (result
!= nullptr)
506 gdb_printf (gdb_stdlog
,
507 "qf->find_compunit_symtab_by_address (...) = %s\n",
509 ? debug_symtab_name (result
->primary_filetab ())
516 objfile::lookup_global_symbol_language (const char *name
,
518 bool *symbol_found_p
)
520 enum language result
= language_unknown
;
521 *symbol_found_p
= false;
523 for (const auto &iter
: qf_require_partial_symbols ())
525 result
= iter
->lookup_global_symbol_language (this, name
, domain
,
535 objfile::require_partial_symbols (bool verbose
)
537 if ((flags
& OBJF_PSYMTABS_READ
) == 0)
539 flags
|= OBJF_PSYMTABS_READ
;
541 bool printed
= false;
542 for (const auto &iter
: qf
)
544 if (iter
->can_lazily_read_symbols ())
546 if (verbose
&& !printed
)
548 gdb_printf (_("Reading symbols from %ps...\n"),
549 styled_string (file_name_style
.style (),
550 objfile_name (this)));
553 iter
->read_partial_symbols (this);
556 if (printed
&& !objfile_has_symbols (this))
557 gdb_printf (_("(No debugging symbols found in %ps)\n"),
558 styled_string (file_name_style
.style (),
559 objfile_name (this)));
563 /* Call LOOKUP_FUNC to find the filename of a file containing the separate
564 debug information matching OBJFILE. If LOOKUP_FUNC does return a
565 filename then open this file and return a std::pair containing the
566 gdb_bfd_ref_ptr of the open file and the filename returned by
567 LOOKUP_FUNC, otherwise this function returns an empty pair; the first
568 item will be nullptr, and the second will be an empty string.
570 Any warnings generated by this function, or by calling LOOKUP_FUNC are
571 placed into WARNINGS, these warnings are only displayed to the user if
572 GDB is unable to find the separate debug information via any route. */
573 static std::pair
<gdb_bfd_ref_ptr
, std::string
>
574 simple_find_and_open_separate_symbol_file
575 (struct objfile
*objfile
,
576 std::string (*lookup_func
) (struct objfile
*, deferred_warnings
*),
577 deferred_warnings
*warnings
)
579 std::string filename
= lookup_func (objfile
, warnings
);
581 if (!filename
.empty ())
583 gdb_bfd_ref_ptr symfile_bfd
584 = symfile_bfd_open_no_error (filename
.c_str ());
585 if (symfile_bfd
!= nullptr)
586 return { symfile_bfd
, filename
};
592 /* Lookup separate debug information for OBJFILE via debuginfod. If
593 successful the debug information will be have been downloaded into the
594 debuginfod cache and this function will return a std::pair containing a
595 gdb_bfd_ref_ptr of the open debug information file and the filename for
596 the file within the debuginfod cache. If no debug information could be
597 found then this function returns an empty pair; the first item will be
598 nullptr, and the second will be an empty string. */
600 static std::pair
<gdb_bfd_ref_ptr
, std::string
>
601 debuginfod_find_and_open_separate_symbol_file (struct objfile
* objfile
)
603 const struct bfd_build_id
*build_id
604 = build_id_bfd_get (objfile
->obfd
.get ());
605 const char *filename
= bfd_get_filename (objfile
->obfd
.get ());
607 if (build_id
!= nullptr)
609 gdb::unique_xmalloc_ptr
<char> symfile_path
;
610 scoped_fd
fd (debuginfod_debuginfo_query (build_id
->data
, build_id
->size
,
611 filename
, &symfile_path
));
615 /* File successfully retrieved from server. */
616 gdb_bfd_ref_ptr debug_bfd
617 (symfile_bfd_open_no_error (symfile_path
.get ()));
619 if (debug_bfd
!= nullptr
620 && build_id_verify (debug_bfd
.get (),
621 build_id
->size
, build_id
->data
))
622 return { debug_bfd
, std::string (symfile_path
.get ()) };
629 /* See objfiles.h. */
632 objfile::find_and_add_separate_symbol_file (symfile_add_flags symfile_flags
)
634 bool has_dwarf2
= false;
636 /* Usually we only make a single pass when looking for separate debug
637 information. However, it is possible for an extension language hook
638 to request that GDB make a second pass, in which case max_attempts
639 will be updated, and the loop restarted. */
640 for (unsigned attempt
= 0, max_attempts
= 1;
641 attempt
< max_attempts
&& !has_dwarf2
;
644 gdb_assert (max_attempts
<= 2);
646 deferred_warnings warnings
;
647 gdb_bfd_ref_ptr debug_bfd
;
648 std::string filename
;
650 std::tie (debug_bfd
, filename
)
651 = simple_find_and_open_separate_symbol_file
652 (this, find_separate_debug_file_by_buildid
, &warnings
);
654 if (debug_bfd
== nullptr)
655 std::tie (debug_bfd
, filename
)
656 = simple_find_and_open_separate_symbol_file
657 (this, find_separate_debug_file_by_debuglink
, &warnings
);
659 /* Only try debuginfod on the first attempt. Sure, we could imagine
660 an extension that somehow adds the required debug info to the
661 debuginfod server but, at least for now, we don't support this
662 scenario. Better for the extension to return new debug info
663 directly to GDB. Plus, going to the debuginfod server might be
664 slow, so that's a good argument for only doing this once. */
665 if (debug_bfd
== nullptr && attempt
== 0)
666 std::tie (debug_bfd
, filename
)
667 = debuginfod_find_and_open_separate_symbol_file (this);
669 if (debug_bfd
!= nullptr)
671 /* We found a separate debug info symbol file. If this is our
672 first attempt then setting HAS_DWARF2 will cause us to break
673 from the attempt loop. */
674 symbol_file_add_separate (debug_bfd
, filename
.c_str (),
675 symfile_flags
, this);
678 else if (attempt
== 0)
680 /* Failed to find a separate debug info symbol file. Call out to
681 the extension languages. The user might have registered an
682 extension that can find the debug info for us, or maybe give
683 the user a system specific message that guides them to finding
684 the missing debug info. */
686 ext_lang_missing_debuginfo_result ext_result
687 = ext_lang_handle_missing_debuginfo (this);
688 if (!ext_result
.filename ().empty ())
690 /* Extension found a suitable debug file for us. */
692 = symfile_bfd_open_no_error (ext_result
.filename ().c_str ());
694 if (debug_bfd
!= nullptr)
696 symbol_file_add_separate (debug_bfd
,
697 ext_result
.filename ().c_str (),
698 symfile_flags
, this);
702 else if (ext_result
.try_again ())
709 /* If we still have not got a separate debug symbol file, then
710 emit any warnings we've collected so far. */
719 /* Debugging version of struct sym_probe_fns. */
721 static const std::vector
<std::unique_ptr
<probe
>> &
722 debug_sym_get_probes (struct objfile
*objfile
)
724 const struct debug_sym_fns_data
*debug_data
725 = symfile_debug_objfile_data_key
.get (objfile
);
727 const std::vector
<std::unique_ptr
<probe
>> &retval
728 = debug_data
->real_sf
->sym_probe_fns
->sym_get_probes (objfile
);
730 gdb_printf (gdb_stdlog
,
731 "probes->sym_get_probes (%s) = %s\n",
732 objfile_debug_name (objfile
),
733 host_address_to_string (retval
.data ()));
738 static const struct sym_probe_fns debug_sym_probe_fns
=
740 debug_sym_get_probes
,
743 /* Debugging version of struct sym_fns. */
746 debug_sym_new_init (struct objfile
*objfile
)
748 const struct debug_sym_fns_data
*debug_data
749 = symfile_debug_objfile_data_key
.get (objfile
);
751 gdb_printf (gdb_stdlog
, "sf->sym_new_init (%s)\n",
752 objfile_debug_name (objfile
));
754 debug_data
->real_sf
->sym_new_init (objfile
);
758 debug_sym_init (struct objfile
*objfile
)
760 const struct debug_sym_fns_data
*debug_data
761 = symfile_debug_objfile_data_key
.get (objfile
);
763 gdb_printf (gdb_stdlog
, "sf->sym_init (%s)\n",
764 objfile_debug_name (objfile
));
766 debug_data
->real_sf
->sym_init (objfile
);
770 debug_sym_read (struct objfile
*objfile
, symfile_add_flags symfile_flags
)
772 const struct debug_sym_fns_data
*debug_data
773 = symfile_debug_objfile_data_key
.get (objfile
);
775 gdb_printf (gdb_stdlog
, "sf->sym_read (%s, 0x%x)\n",
776 objfile_debug_name (objfile
), (unsigned) symfile_flags
);
778 debug_data
->real_sf
->sym_read (objfile
, symfile_flags
);
782 debug_sym_finish (struct objfile
*objfile
)
784 const struct debug_sym_fns_data
*debug_data
785 = symfile_debug_objfile_data_key
.get (objfile
);
787 gdb_printf (gdb_stdlog
, "sf->sym_finish (%s)\n",
788 objfile_debug_name (objfile
));
790 debug_data
->real_sf
->sym_finish (objfile
);
794 debug_sym_offsets (struct objfile
*objfile
,
795 const section_addr_info
&info
)
797 const struct debug_sym_fns_data
*debug_data
798 = symfile_debug_objfile_data_key
.get (objfile
);
800 gdb_printf (gdb_stdlog
, "sf->sym_offsets (%s, %s)\n",
801 objfile_debug_name (objfile
),
802 host_address_to_string (&info
));
804 debug_data
->real_sf
->sym_offsets (objfile
, info
);
807 static symfile_segment_data_up
808 debug_sym_segments (bfd
*abfd
)
810 /* This API function is annoying, it doesn't take a "this" pointer.
811 Fortunately it is only used in one place where we (re-)lookup the
812 sym_fns table to use. Thus we will never be called. */
813 gdb_assert_not_reached ("debug_sym_segments called");
817 debug_sym_read_linetable (struct objfile
*objfile
)
819 const struct debug_sym_fns_data
*debug_data
820 = symfile_debug_objfile_data_key
.get (objfile
);
822 gdb_printf (gdb_stdlog
, "sf->sym_read_linetable (%s)\n",
823 objfile_debug_name (objfile
));
825 debug_data
->real_sf
->sym_read_linetable (objfile
);
829 debug_sym_relocate (struct objfile
*objfile
, asection
*sectp
, bfd_byte
*buf
)
831 const struct debug_sym_fns_data
*debug_data
832 = symfile_debug_objfile_data_key
.get (objfile
);
835 retval
= debug_data
->real_sf
->sym_relocate (objfile
, sectp
, buf
);
837 gdb_printf (gdb_stdlog
,
838 "sf->sym_relocate (%s, %s, %s) = %s\n",
839 objfile_debug_name (objfile
),
840 host_address_to_string (sectp
),
841 host_address_to_string (buf
),
842 host_address_to_string (retval
));
847 /* Template of debugging version of struct sym_fns.
848 A copy is made, with sym_flavour updated, and a pointer to the real table
849 installed in real_sf, and then a pointer to the copy is installed in the
852 static const struct sym_fns debug_sym_fns
=
860 debug_sym_read_linetable
,
862 &debug_sym_probe_fns
,
865 /* Install the debugging versions of the symfile functions for OBJFILE.
866 Do not call this if the debug versions are already installed. */
869 install_symfile_debug_logging (struct objfile
*objfile
)
871 const struct sym_fns
*real_sf
;
872 struct debug_sym_fns_data
*debug_data
;
874 /* The debug versions should not already be installed. */
875 gdb_assert (!symfile_debug_installed (objfile
));
877 real_sf
= objfile
->sf
;
879 /* Alas we have to preserve NULL entries in REAL_SF. */
880 debug_data
= new struct debug_sym_fns_data
;
882 #define COPY_SF_PTR(from, to, name, func) \
885 (to)->debug_sf.name = func; \
888 COPY_SF_PTR (real_sf
, debug_data
, sym_new_init
, debug_sym_new_init
);
889 COPY_SF_PTR (real_sf
, debug_data
, sym_init
, debug_sym_init
);
890 COPY_SF_PTR (real_sf
, debug_data
, sym_read
, debug_sym_read
);
891 COPY_SF_PTR (real_sf
, debug_data
, sym_finish
, debug_sym_finish
);
892 COPY_SF_PTR (real_sf
, debug_data
, sym_offsets
, debug_sym_offsets
);
893 COPY_SF_PTR (real_sf
, debug_data
, sym_segments
, debug_sym_segments
);
894 COPY_SF_PTR (real_sf
, debug_data
, sym_read_linetable
,
895 debug_sym_read_linetable
);
896 COPY_SF_PTR (real_sf
, debug_data
, sym_relocate
, debug_sym_relocate
);
897 if (real_sf
->sym_probe_fns
)
898 debug_data
->debug_sf
.sym_probe_fns
= &debug_sym_probe_fns
;
902 debug_data
->real_sf
= real_sf
;
903 symfile_debug_objfile_data_key
.set (objfile
, debug_data
);
904 objfile
->sf
= &debug_data
->debug_sf
;
907 /* Uninstall the debugging versions of the symfile functions for OBJFILE.
908 Do not call this if the debug versions are not installed. */
911 uninstall_symfile_debug_logging (struct objfile
*objfile
)
913 struct debug_sym_fns_data
*debug_data
;
915 /* The debug versions should be currently installed. */
916 gdb_assert (symfile_debug_installed (objfile
));
918 debug_data
= symfile_debug_objfile_data_key
.get (objfile
);
920 objfile
->sf
= debug_data
->real_sf
;
921 symfile_debug_objfile_data_key
.clear (objfile
);
924 /* Call this function to set OBJFILE->SF.
925 Do not set OBJFILE->SF directly. */
928 objfile_set_sym_fns (struct objfile
*objfile
, const struct sym_fns
*sf
)
930 if (symfile_debug_installed (objfile
))
932 gdb_assert (debug_symfile
);
933 /* Remove the current one, and reinstall a new one later. */
934 uninstall_symfile_debug_logging (objfile
);
937 /* Assume debug logging is disabled. */
940 /* Turn debug logging on if enabled. */
942 install_symfile_debug_logging (objfile
);
946 set_debug_symfile (const char *args
, int from_tty
, struct cmd_list_element
*c
)
948 for (struct program_space
*pspace
: program_spaces
)
949 for (objfile
*objfile
: pspace
->objfiles ())
953 if (!symfile_debug_installed (objfile
))
954 install_symfile_debug_logging (objfile
);
958 if (symfile_debug_installed (objfile
))
959 uninstall_symfile_debug_logging (objfile
);
965 show_debug_symfile (struct ui_file
*file
, int from_tty
,
966 struct cmd_list_element
*c
, const char *value
)
968 gdb_printf (file
, _("Symfile debugging is %s.\n"), value
);
971 void _initialize_symfile_debug ();
973 _initialize_symfile_debug ()
975 add_setshow_boolean_cmd ("symfile", no_class
, &debug_symfile
, _("\
976 Set debugging of the symfile functions."), _("\
977 Show debugging of the symfile functions."), _("\
978 When enabled, all calls to the symfile functions are logged."),
979 set_debug_symfile
, show_debug_symfile
,
980 &setdebuglist
, &showdebuglist
);
982 /* Note: We don't need a new-objfile observer because debug logging
983 will be installed when objfile init'n calls objfile_set_sym_fns. */