Remove quick_symbol_functions::lookup_symbol
[deliverable/binutils-gdb.git] / gdb / symfile-debug.c
CommitLineData
8fb8eb5c
DE
1/* Debug logging for the symbol file functions for the GNU debugger, GDB.
2
3666a048 3 Copyright (C) 2013-2021 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"
76727919 31#include "observable.h"
8fb8eb5c
DE
32#include "source.h"
33#include "symtab.h"
34#include "symfile.h"
84d865e3 35#include "block.h"
8fb8eb5c
DE
36
37/* We need to save a pointer to the real symbol functions.
38 Plus, the debug versions are malloc'd because we have to NULL out the
39 ones that are NULL in the real copy. */
40
41struct debug_sym_fns_data
42{
8c42777c
TT
43 const struct sym_fns *real_sf = nullptr;
44 struct sym_fns debug_sf {};
8fb8eb5c
DE
45};
46
47/* We need to record a pointer to the real set of functions for each
48 objfile. */
8c42777c
TT
49static const struct objfile_key<debug_sym_fns_data>
50 symfile_debug_objfile_data_key;
8fb8eb5c 51
491144b5
CB
52/* If true all calls to the symfile functions are logged. */
53static bool debug_symfile = false;
8fb8eb5c
DE
54
55/* Return non-zero if symfile debug logging is installed. */
56
57static int
58symfile_debug_installed (struct objfile *objfile)
59{
60 return (objfile->sf != NULL
8c42777c 61 && symfile_debug_objfile_data_key.get (objfile) != NULL);
8fb8eb5c
DE
62}
63
8fb8eb5c
DE
64/* Utility return the name to print for SYMTAB. */
65
66static const char *
67debug_symtab_name (struct symtab *symtab)
68{
69 return symtab_to_filename_for_display (symtab);
70}
71\f
8fb8eb5c 72
4d080b46
TT
73/* See objfiles.h. */
74
75bool
76objfile::has_partial_symbols ()
8fb8eb5c 77{
4d080b46 78 bool retval = false;
8fb8eb5c 79
4d080b46
TT
80 /* If we have not read psymbols, but we have a function capable of reading
81 them, then that is an indication that they are in fact available. Without
82 this function the symbols may have been already read in but they also may
83 not be present in this objfile. */
e1114590
TT
84 for (const auto &iter : qf)
85 {
86 if ((flags & OBJF_PSYMTABS_READ) == 0
87 && iter->can_lazily_read_symbols ())
88 retval = true;
89 else
90 retval = iter->has_symbols (this);
91 if (retval)
92 break;
93 }
8fb8eb5c 94
4d080b46
TT
95 if (debug_symfile)
96 fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n",
97 objfile_debug_name (this), retval);
8fb8eb5c
DE
98
99 return retval;
100}
101
4d080b46
TT
102struct symtab *
103objfile::find_last_source_symtab ()
8fb8eb5c 104{
4d080b46 105 struct symtab *retval = nullptr;
8fb8eb5c 106
4d080b46
TT
107 if (debug_symfile)
108 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
109 objfile_debug_name (this));
8fb8eb5c 110
e1114590
TT
111 for (const auto &iter : qf)
112 {
113 retval = iter->find_last_source_symtab (this);
114 if (retval != nullptr)
115 break;
116 }
8fb8eb5c 117
4d080b46
TT
118 if (debug_symfile)
119 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n",
120 retval ? debug_symtab_name (retval) : "NULL");
8fb8eb5c
DE
121
122 return retval;
123}
124
4d080b46
TT
125void
126objfile::forget_cached_source_info ()
8fb8eb5c 127{
4d080b46
TT
128 if (debug_symfile)
129 fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
130 objfile_debug_name (this));
8fb8eb5c 131
e1114590
TT
132 for (const auto &iter : qf)
133 iter->forget_cached_source_info (this);
8fb8eb5c
DE
134}
135
4d080b46
TT
136bool
137objfile::map_symtabs_matching_filename
138 (const char *name, const char *real_path,
14bc53a8 139 gdb::function_view<bool (symtab *)> callback)
8fb8eb5c 140{
4d080b46
TT
141 if (debug_symfile)
142 fprintf_filtered (gdb_stdlog,
143 "qf->map_symtabs_matching_filename (%s, \"%s\", "
144 "\"%s\", %s)\n",
145 objfile_debug_name (this), name,
146 real_path ? real_path : NULL,
147 host_address_to_string (&callback));
8fb8eb5c 148
4d080b46 149 bool retval = false;
e1114590
TT
150 for (const auto &iter : qf)
151 {
152 retval = (iter->map_symtabs_matching_filename
153 (this, name, real_path, callback));
154 if (retval)
155 break;
156 }
8fb8eb5c 157
4d080b46
TT
158 if (debug_symfile)
159 fprintf_filtered (gdb_stdlog,
160 "qf->map_symtabs_matching_filename (...) = %d\n",
161 retval);
8fb8eb5c
DE
162
163 return retval;
164}
165
4d080b46
TT
166struct compunit_symtab *
167objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
8fb8eb5c 168{
4d080b46 169 struct compunit_symtab *retval = nullptr;
8fb8eb5c 170
4d080b46
TT
171 if (debug_symfile)
172 fprintf_filtered (gdb_stdlog,
173 "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
174 objfile_debug_name (this), kind, name,
175 domain_name (domain));
8fb8eb5c 176
84d865e3
TT
177 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
178
179 auto search_one_symtab = [&] (compunit_symtab *stab)
180 {
181 struct symbol *sym, *with_opaque = NULL;
182 const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
183 const struct block *block = BLOCKVECTOR_BLOCK (bv, kind);
184
185 sym = block_find_symbol (block, name, domain,
186 block_find_non_opaque_type_preferred,
187 &with_opaque);
188
189 /* Some caution must be observed with overloaded functions
190 and methods, since the index will not contain any overload
191 information (but NAME might contain it). */
192
193 if (sym != NULL
194 && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
195 {
196 retval = stab;
197 /* Found it. */
198 return false;
199 }
200 if (with_opaque != NULL
201 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
202 retval = stab;
203
204 /* Keep looking through other psymtabs. */
205 return true;
206 };
207
e1114590
TT
208 for (const auto &iter : qf)
209 {
84d865e3
TT
210 if (!iter->expand_symtabs_matching (this,
211 nullptr,
212 &lookup_name,
213 nullptr,
214 search_one_symtab,
215 kind == GLOBAL_BLOCK
216 ? SEARCH_GLOBAL_BLOCK
217 : SEARCH_STATIC_BLOCK,
218 domain,
219 ALL_DOMAIN))
e1114590
TT
220 break;
221 }
8fb8eb5c 222
4d080b46
TT
223 if (debug_symfile)
224 fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
225 retval
226 ? debug_symtab_name (compunit_primary_filetab (retval))
227 : "NULL");
8fb8eb5c
DE
228
229 return retval;
230}
231
4d080b46 232void
4829711b 233objfile::print_stats (bool print_bcache)
8fb8eb5c 234{
4d080b46 235 if (debug_symfile)
4829711b
TT
236 fprintf_filtered (gdb_stdlog, "qf->print_stats (%s, %d)\n",
237 objfile_debug_name (this), print_bcache);
8fb8eb5c 238
e1114590
TT
239 for (const auto &iter : qf)
240 iter->print_stats (this, print_bcache);
8fb8eb5c
DE
241}
242
4d080b46
TT
243void
244objfile::dump ()
8fb8eb5c 245{
4d080b46
TT
246 if (debug_symfile)
247 fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
248 objfile_debug_name (this));
8fb8eb5c 249
e1114590
TT
250 for (const auto &iter : qf)
251 iter->dump (this);
8fb8eb5c
DE
252}
253
4d080b46
TT
254void
255objfile::expand_symtabs_for_function (const char *func_name)
8fb8eb5c 256{
4d080b46
TT
257 if (debug_symfile)
258 fprintf_filtered (gdb_stdlog,
259 "qf->expand_symtabs_for_function (%s, \"%s\")\n",
260 objfile_debug_name (this), func_name);
8fb8eb5c 261
e1114590
TT
262 for (const auto &iter : qf)
263 iter->expand_symtabs_for_function (this, func_name);
8fb8eb5c
DE
264}
265
4d080b46
TT
266void
267objfile::expand_all_symtabs ()
8fb8eb5c 268{
4d080b46
TT
269 if (debug_symfile)
270 fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
271 objfile_debug_name (this));
8fb8eb5c 272
e1114590
TT
273 for (const auto &iter : qf)
274 iter->expand_all_symtabs (this);
8fb8eb5c
DE
275}
276
4d080b46
TT
277void
278objfile::expand_symtabs_with_fullname (const char *fullname)
8fb8eb5c 279{
4d080b46
TT
280 if (debug_symfile)
281 fprintf_filtered (gdb_stdlog,
282 "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
283 objfile_debug_name (this), fullname);
8fb8eb5c 284
e1114590
TT
285 for (const auto &iter : qf)
286 iter->expand_symtabs_with_fullname (this, fullname);
8fb8eb5c
DE
287}
288
4d080b46
TT
289void
290objfile::map_matching_symbols
291 (const lookup_name_info &name, domain_enum domain,
199b4314
TT
292 int global,
293 gdb::function_view<symbol_found_callback_ftype> callback,
199b4314 294 symbol_compare_ftype *ordered_compare)
8fb8eb5c 295{
4d080b46
TT
296 if (debug_symfile)
297 fprintf_filtered (gdb_stdlog,
298 "qf->map_matching_symbols (%s, %s, %d, %s)\n",
299 objfile_debug_name (this),
300 domain_name (domain), global,
301 host_address_to_string (ordered_compare));
8fb8eb5c 302
e1114590
TT
303 for (const auto &iter : qf)
304 iter->map_matching_symbols (this, name, domain, global,
305 callback, ordered_compare);
8fb8eb5c
DE
306}
307
df35e626 308bool
4d080b46
TT
309objfile::expand_symtabs_matching
310 (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
c1a66c06 311 const lookup_name_info *lookup_name,
14bc53a8
PA
312 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
313 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
03a8ea51 314 block_search_flags search_flags,
3bfa51a7 315 domain_enum domain,
14bc53a8 316 enum search_domain kind)
8fb8eb5c 317{
4d080b46
TT
318 if (debug_symfile)
319 fprintf_filtered (gdb_stdlog,
320 "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
321 objfile_debug_name (this),
322 host_address_to_string (&file_matcher),
323 host_address_to_string (&symbol_matcher),
324 host_address_to_string (&expansion_notify),
325 search_domain_name (kind));
326
e1114590 327 for (const auto &iter : qf)
df35e626
TT
328 if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name,
329 symbol_matcher, expansion_notify,
3bfa51a7 330 search_flags, domain, kind))
df35e626
TT
331 return false;
332 return true;
8fb8eb5c
DE
333}
334
4d080b46
TT
335struct compunit_symtab *
336objfile::find_pc_sect_compunit_symtab (struct bound_minimal_symbol msymbol,
43f3e411
DE
337 CORE_ADDR pc,
338 struct obj_section *section,
339 int warn_if_readin)
8fb8eb5c 340{
4d080b46
TT
341 struct compunit_symtab *retval = nullptr;
342
343 if (debug_symfile)
344 fprintf_filtered (gdb_stdlog,
345 "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n",
346 objfile_debug_name (this),
347 host_address_to_string (msymbol.minsym),
348 hex_string (pc),
349 host_address_to_string (section),
350 warn_if_readin);
351
e1114590
TT
352 for (const auto &iter : qf)
353 {
354 retval = iter->find_pc_sect_compunit_symtab (this, msymbol, pc, section,
355 warn_if_readin);
356 if (retval != nullptr)
357 break;
358 }
4d080b46
TT
359
360 if (debug_symfile)
361 fprintf_filtered (gdb_stdlog,
362 "qf->find_pc_sect_compunit_symtab (...) = %s\n",
363 retval
364 ? debug_symtab_name (compunit_primary_filetab (retval))
365 : "NULL");
8fb8eb5c
DE
366
367 return retval;
368}
369
4d080b46 370void
f4655dee
TT
371objfile::map_symbol_filenames (gdb::function_view<symbol_filename_ftype> fun,
372 bool need_fullname)
8fb8eb5c 373{
4d080b46
TT
374 if (debug_symfile)
375 fprintf_filtered (gdb_stdlog,
f4655dee 376 "qf->map_symbol_filenames (%s, ..., %d)\n",
4d080b46 377 objfile_debug_name (this),
4d080b46 378 need_fullname);
8fb8eb5c 379
e1114590 380 for (const auto &iter : qf)
f4655dee 381 iter->map_symbol_filenames (this, fun, need_fullname);
8fb8eb5c
DE
382}
383
4d080b46
TT
384struct compunit_symtab *
385objfile::find_compunit_symtab_by_address (CORE_ADDR address)
71a3c369 386{
4d080b46
TT
387 if (debug_symfile)
388 fprintf_filtered (gdb_stdlog,
389 "qf->find_compunit_symtab_by_address (%s, %s)\n",
390 objfile_debug_name (this),
391 hex_string (address));
71a3c369
TT
392
393 struct compunit_symtab *result = NULL;
e1114590
TT
394 for (const auto &iter : qf)
395 {
396 result = iter->find_compunit_symtab_by_address (this, address);
397 if (result != nullptr)
398 break;
399 }
71a3c369 400
4d080b46
TT
401 if (debug_symfile)
402 fprintf_filtered (gdb_stdlog,
403 "qf->find_compunit_symtab_by_address (...) = %s\n",
404 result
405 ? debug_symtab_name (compunit_primary_filetab (result))
406 : "NULL");
407
408 return result;
409}
410
411enum language
412objfile::lookup_global_symbol_language (const char *name,
413 domain_enum domain,
414 bool *symbol_found_p)
415{
416 enum language result = language_unknown;
e1114590 417 *symbol_found_p = false;
4d080b46 418
e1114590
TT
419 for (const auto &iter : qf)
420 {
421 result = iter->lookup_global_symbol_language (this, name, domain,
422 symbol_found_p);
423 if (*symbol_found_p)
424 break;
425 }
71a3c369
TT
426
427 return result;
428}
429
d1eef86d
TT
430void
431objfile::require_partial_symbols (bool verbose)
432{
433 if ((flags & OBJF_PSYMTABS_READ) == 0)
434 {
435 flags |= OBJF_PSYMTABS_READ;
436
e1114590
TT
437 bool printed = false;
438 for (const auto &iter : qf)
d1eef86d 439 {
e1114590
TT
440 if (iter->can_lazily_read_symbols ())
441 {
442 if (verbose && !printed)
443 {
444 printf_filtered (_("Reading symbols from %s...\n"),
445 objfile_name (this));
446 printed = true;
447 }
448 iter->read_partial_symbols (this);
449 }
d1eef86d 450 }
e1114590
TT
451 if (printed && !objfile_has_symbols (this))
452 printf_filtered (_("(No debugging symbols found in %s)\n"),
453 objfile_name (this));
d1eef86d
TT
454 }
455}
456
8fb8eb5c
DE
457\f
458/* Debugging version of struct sym_probe_fns. */
459
814cf43a 460static const std::vector<std::unique_ptr<probe>> &
8fb8eb5c
DE
461debug_sym_get_probes (struct objfile *objfile)
462{
19ba03f4 463 const struct debug_sym_fns_data *debug_data
8c42777c 464 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c 465
814cf43a 466 const std::vector<std::unique_ptr<probe>> &retval
aaa63a31 467 = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile);
8fb8eb5c
DE
468
469 fprintf_filtered (gdb_stdlog,
470 "probes->sym_get_probes (%s) = %s\n",
cc485e62 471 objfile_debug_name (objfile),
aaa63a31 472 host_address_to_string (retval.data ()));
8fb8eb5c
DE
473
474 return retval;
475}
476
8fb8eb5c
DE
477static const struct sym_probe_fns debug_sym_probe_fns =
478{
479 debug_sym_get_probes,
8fb8eb5c
DE
480};
481\f
482/* Debugging version of struct sym_fns. */
483
484static void
485debug_sym_new_init (struct objfile *objfile)
486{
19ba03f4 487 const struct debug_sym_fns_data *debug_data
8c42777c 488 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
489
490 fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n",
cc485e62 491 objfile_debug_name (objfile));
8fb8eb5c
DE
492
493 debug_data->real_sf->sym_new_init (objfile);
494}
495
496static void
497debug_sym_init (struct objfile *objfile)
498{
19ba03f4 499 const struct debug_sym_fns_data *debug_data
8c42777c 500 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
501
502 fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n",
cc485e62 503 objfile_debug_name (objfile));
8fb8eb5c
DE
504
505 debug_data->real_sf->sym_init (objfile);
506}
507
508static void
b15cc25c 509debug_sym_read (struct objfile *objfile, symfile_add_flags symfile_flags)
8fb8eb5c 510{
19ba03f4 511 const struct debug_sym_fns_data *debug_data
8c42777c 512 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
513
514 fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n",
b15cc25c 515 objfile_debug_name (objfile), (unsigned) symfile_flags);
8fb8eb5c
DE
516
517 debug_data->real_sf->sym_read (objfile, symfile_flags);
518}
519
8fb8eb5c
DE
520static void
521debug_sym_finish (struct objfile *objfile)
522{
19ba03f4 523 const struct debug_sym_fns_data *debug_data
8c42777c 524 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
525
526 fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n",
cc485e62 527 objfile_debug_name (objfile));
8fb8eb5c
DE
528
529 debug_data->real_sf->sym_finish (objfile);
530}
531
532static void
533debug_sym_offsets (struct objfile *objfile,
37e136b1 534 const section_addr_info &info)
8fb8eb5c 535{
19ba03f4 536 const struct debug_sym_fns_data *debug_data
8c42777c 537 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
538
539 fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n",
cc485e62 540 objfile_debug_name (objfile),
37e136b1 541 host_address_to_string (&info));
8fb8eb5c
DE
542
543 debug_data->real_sf->sym_offsets (objfile, info);
544}
545
62982abd 546static symfile_segment_data_up
8fb8eb5c
DE
547debug_sym_segments (bfd *abfd)
548{
549 /* This API function is annoying, it doesn't take a "this" pointer.
550 Fortunately it is only used in one place where we (re-)lookup the
551 sym_fns table to use. Thus we will never be called. */
552 gdb_assert_not_reached ("debug_sym_segments called");
553}
554
555static void
556debug_sym_read_linetable (struct objfile *objfile)
557{
19ba03f4 558 const struct debug_sym_fns_data *debug_data
8c42777c 559 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
560
561 fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n",
cc485e62 562 objfile_debug_name (objfile));
8fb8eb5c
DE
563
564 debug_data->real_sf->sym_read_linetable (objfile);
565}
566
567static bfd_byte *
568debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf)
569{
19ba03f4 570 const struct debug_sym_fns_data *debug_data
8c42777c 571 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
572 bfd_byte *retval;
573
574 retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf);
575
576 fprintf_filtered (gdb_stdlog,
577 "sf->sym_relocate (%s, %s, %s) = %s\n",
cc485e62 578 objfile_debug_name (objfile),
8fb8eb5c
DE
579 host_address_to_string (sectp),
580 host_address_to_string (buf),
581 host_address_to_string (retval));
582
583 return retval;
584}
585
586/* Template of debugging version of struct sym_fns.
587 A copy is made, with sym_flavour updated, and a pointer to the real table
588 installed in real_sf, and then a pointer to the copy is installed in the
589 objfile. */
590
591static const struct sym_fns debug_sym_fns =
592{
593 debug_sym_new_init,
594 debug_sym_init,
595 debug_sym_read,
8fb8eb5c
DE
596 debug_sym_finish,
597 debug_sym_offsets,
598 debug_sym_segments,
599 debug_sym_read_linetable,
600 debug_sym_relocate,
601 &debug_sym_probe_fns,
8fb8eb5c
DE
602};
603\f
8fb8eb5c
DE
604/* Install the debugging versions of the symfile functions for OBJFILE.
605 Do not call this if the debug versions are already installed. */
606
607static void
608install_symfile_debug_logging (struct objfile *objfile)
609{
610 const struct sym_fns *real_sf;
611 struct debug_sym_fns_data *debug_data;
612
613 /* The debug versions should not already be installed. */
614 gdb_assert (!symfile_debug_installed (objfile));
615
616 real_sf = objfile->sf;
617
618 /* Alas we have to preserve NULL entries in REAL_SF. */
8c42777c 619 debug_data = new struct debug_sym_fns_data;
8fb8eb5c
DE
620
621#define COPY_SF_PTR(from, to, name, func) \
622 do { \
623 if ((from)->name) \
624 (to)->debug_sf.name = func; \
625 } while (0)
626
627 COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init);
628 COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init);
629 COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read);
8fb8eb5c
DE
630 COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish);
631 COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets);
632 COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments);
633 COPY_SF_PTR (real_sf, debug_data, sym_read_linetable,
634 debug_sym_read_linetable);
635 COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate);
636 if (real_sf->sym_probe_fns)
637 debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns;
8fb8eb5c
DE
638
639#undef COPY_SF_PTR
640
641 debug_data->real_sf = real_sf;
8c42777c 642 symfile_debug_objfile_data_key.set (objfile, debug_data);
8fb8eb5c
DE
643 objfile->sf = &debug_data->debug_sf;
644}
645
646/* Uninstall the debugging versions of the symfile functions for OBJFILE.
647 Do not call this if the debug versions are not installed. */
648
649static void
650uninstall_symfile_debug_logging (struct objfile *objfile)
651{
652 struct debug_sym_fns_data *debug_data;
653
654 /* The debug versions should be currently installed. */
655 gdb_assert (symfile_debug_installed (objfile));
656
8c42777c 657 debug_data = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
658
659 objfile->sf = debug_data->real_sf;
8c42777c 660 symfile_debug_objfile_data_key.clear (objfile);
8fb8eb5c
DE
661}
662
663/* Call this function to set OBJFILE->SF.
664 Do not set OBJFILE->SF directly. */
665
666void
667objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf)
668{
669 if (symfile_debug_installed (objfile))
670 {
671 gdb_assert (debug_symfile);
672 /* Remove the current one, and reinstall a new one later. */
673 uninstall_symfile_debug_logging (objfile);
674 }
675
676 /* Assume debug logging is disabled. */
677 objfile->sf = sf;
678
679 /* Turn debug logging on if enabled. */
680 if (debug_symfile)
681 install_symfile_debug_logging (objfile);
682}
683
684static void
eb4c3f4a 685set_debug_symfile (const char *args, int from_tty, struct cmd_list_element *c)
8fb8eb5c 686{
94c93c35 687 for (struct program_space *pspace : program_spaces)
2030c079 688 for (objfile *objfile : pspace->objfiles ())
99d89cde
TT
689 {
690 if (debug_symfile)
691 {
692 if (!symfile_debug_installed (objfile))
693 install_symfile_debug_logging (objfile);
694 }
695 else
696 {
697 if (symfile_debug_installed (objfile))
698 uninstall_symfile_debug_logging (objfile);
699 }
700 }
8fb8eb5c
DE
701}
702
703static void
704show_debug_symfile (struct ui_file *file, int from_tty,
705 struct cmd_list_element *c, const char *value)
706{
707 fprintf_filtered (file, _("Symfile debugging is %s.\n"), value);
708}
709
6c265988 710void _initialize_symfile_debug ();
8fb8eb5c 711void
6c265988 712_initialize_symfile_debug ()
8fb8eb5c 713{
8fb8eb5c
DE
714 add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\
715Set debugging of the symfile functions."), _("\
716Show debugging of the symfile functions."), _("\
717When enabled, all calls to the symfile functions are logged."),
718 set_debug_symfile, show_debug_symfile,
719 &setdebuglist, &showdebuglist);
720
721 /* Note: We don't need a new-objfile observer because debug logging
722 will be installed when objfile init'n calls objfile_set_sym_fns. */
723}
This page took 0.920557 seconds and 4 git commands to generate.