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