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