gdb: add target_ops::supports_displaced_step
[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
b811d2c2 3 Copyright (C) 2013-2020 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 50
491144b5
CB
51/* If true all calls to the symfile functions are logged. */
52static bool debug_symfile = false;
8fb8eb5c
DE
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,
b054970d 233 const lookup_name_info &name, domain_enum domain,
199b4314
TT
234 int global,
235 gdb::function_view<symbol_found_callback_ftype> callback,
199b4314 236 symbol_compare_ftype *ordered_compare)
8fb8eb5c 237{
19ba03f4 238 const struct debug_sym_fns_data *debug_data
8c42777c 239 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
240
241 fprintf_filtered (gdb_stdlog,
b054970d
TT
242 "qf->map_matching_symbols (%s, %s, %d, %s)\n",
243 objfile_debug_name (objfile),
fe978cb0 244 domain_name (domain), global,
8fb8eb5c
DE
245 host_address_to_string (ordered_compare));
246
247 debug_data->real_sf->qf->map_matching_symbols (objfile, name,
fe978cb0 248 domain, global,
199b4314 249 callback,
8fb8eb5c
DE
250 ordered_compare);
251}
252
253static void
e86b67d3
JB
254debug_qf_expand_symtabs_matching
255 (struct objfile *objfile,
14bc53a8 256 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
c1a66c06 257 const lookup_name_info *lookup_name,
14bc53a8
PA
258 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
259 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
260 enum search_domain kind)
8fb8eb5c 261{
19ba03f4 262 const struct debug_sym_fns_data *debug_data
8c42777c 263 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
264
265 fprintf_filtered (gdb_stdlog,
14bc53a8 266 "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
cc485e62 267 objfile_debug_name (objfile),
14bc53a8
PA
268 host_address_to_string (&file_matcher),
269 host_address_to_string (&symbol_matcher),
270 host_address_to_string (&expansion_notify),
271 search_domain_name (kind));
8fb8eb5c
DE
272
273 debug_data->real_sf->qf->expand_symtabs_matching (objfile,
274 file_matcher,
b5ec771e 275 lookup_name,
3f03e7b1 276 symbol_matcher,
276d885b 277 expansion_notify,
14bc53a8 278 kind);
8fb8eb5c
DE
279}
280
43f3e411
DE
281static struct compunit_symtab *
282debug_qf_find_pc_sect_compunit_symtab (struct objfile *objfile,
283 struct bound_minimal_symbol msymbol,
284 CORE_ADDR pc,
285 struct obj_section *section,
286 int warn_if_readin)
8fb8eb5c 287{
19ba03f4 288 const struct debug_sym_fns_data *debug_data
8c42777c 289 = symfile_debug_objfile_data_key.get (objfile);
43f3e411 290 struct compunit_symtab *retval;
8fb8eb5c
DE
291
292 fprintf_filtered (gdb_stdlog,
43f3e411 293 "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n",
cc485e62 294 objfile_debug_name (objfile),
77e371c0 295 host_address_to_string (msymbol.minsym),
8fb8eb5c
DE
296 hex_string (pc),
297 host_address_to_string (section),
298 warn_if_readin);
299
43f3e411
DE
300 retval
301 = debug_data->real_sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol,
302 pc, section,
303 warn_if_readin);
8fb8eb5c 304
43f3e411
DE
305 fprintf_filtered (gdb_stdlog,
306 "qf->find_pc_sect_compunit_symtab (...) = %s\n",
307 retval
308 ? debug_symtab_name (compunit_primary_filetab (retval))
309 : "NULL");
8fb8eb5c
DE
310
311 return retval;
312}
313
314static void
315debug_qf_map_symbol_filenames (struct objfile *objfile,
316 symbol_filename_ftype *fun, void *data,
317 int need_fullname)
318{
19ba03f4 319 const struct debug_sym_fns_data *debug_data
8c42777c 320 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
321 fprintf_filtered (gdb_stdlog,
322 "qf->map_symbol_filenames (%s, %s, %s, %d)\n",
cc485e62 323 objfile_debug_name (objfile),
8fb8eb5c
DE
324 host_address_to_string (fun),
325 host_address_to_string (data),
326 need_fullname);
327
328 debug_data->real_sf->qf->map_symbol_filenames (objfile, fun, data,
329 need_fullname);
330}
331
71a3c369
TT
332static struct compunit_symtab *
333debug_qf_find_compunit_symtab_by_address (struct objfile *objfile,
334 CORE_ADDR address)
335{
336 const struct debug_sym_fns_data *debug_data
8c42777c 337 = symfile_debug_objfile_data_key.get (objfile);
71a3c369
TT
338 fprintf_filtered (gdb_stdlog,
339 "qf->find_compunit_symtab_by_address (%s, %s)\n",
340 objfile_debug_name (objfile),
341 hex_string (address));
342
343 struct compunit_symtab *result = NULL;
344 if (debug_data->real_sf->qf->map_symbol_filenames != NULL)
345 result
346 = debug_data->real_sf->qf->find_compunit_symtab_by_address (objfile,
347 address);
348
349 fprintf_filtered (gdb_stdlog,
350 "qf->find_compunit_symtab_by_address (...) = %s\n",
351 result
352 ? debug_symtab_name (compunit_primary_filetab (result))
353 : "NULL");
354
355 return result;
356}
357
8fb8eb5c
DE
358static const struct quick_symbol_functions debug_sym_quick_functions =
359{
360 debug_qf_has_symbols,
361 debug_qf_find_last_source_symtab,
362 debug_qf_forget_cached_source_info,
363 debug_qf_map_symtabs_matching_filename,
364 debug_qf_lookup_symbol,
d3214198 365 NULL,
8fb8eb5c
DE
366 debug_qf_print_stats,
367 debug_qf_dump,
8fb8eb5c
DE
368 debug_qf_expand_symtabs_for_function,
369 debug_qf_expand_all_symtabs,
370 debug_qf_expand_symtabs_with_fullname,
371 debug_qf_map_matching_symbols,
372 debug_qf_expand_symtabs_matching,
43f3e411 373 debug_qf_find_pc_sect_compunit_symtab,
71a3c369 374 debug_qf_find_compunit_symtab_by_address,
8fb8eb5c
DE
375 debug_qf_map_symbol_filenames
376};
377\f
378/* Debugging version of struct sym_probe_fns. */
379
814cf43a 380static const std::vector<std::unique_ptr<probe>> &
8fb8eb5c
DE
381debug_sym_get_probes (struct objfile *objfile)
382{
19ba03f4 383 const struct debug_sym_fns_data *debug_data
8c42777c 384 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c 385
814cf43a 386 const std::vector<std::unique_ptr<probe>> &retval
aaa63a31 387 = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile);
8fb8eb5c
DE
388
389 fprintf_filtered (gdb_stdlog,
390 "probes->sym_get_probes (%s) = %s\n",
cc485e62 391 objfile_debug_name (objfile),
aaa63a31 392 host_address_to_string (retval.data ()));
8fb8eb5c
DE
393
394 return retval;
395}
396
8fb8eb5c
DE
397static const struct sym_probe_fns debug_sym_probe_fns =
398{
399 debug_sym_get_probes,
8fb8eb5c
DE
400};
401\f
402/* Debugging version of struct sym_fns. */
403
404static void
405debug_sym_new_init (struct objfile *objfile)
406{
19ba03f4 407 const struct debug_sym_fns_data *debug_data
8c42777c 408 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
409
410 fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n",
cc485e62 411 objfile_debug_name (objfile));
8fb8eb5c
DE
412
413 debug_data->real_sf->sym_new_init (objfile);
414}
415
416static void
417debug_sym_init (struct objfile *objfile)
418{
19ba03f4 419 const struct debug_sym_fns_data *debug_data
8c42777c 420 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
421
422 fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n",
cc485e62 423 objfile_debug_name (objfile));
8fb8eb5c
DE
424
425 debug_data->real_sf->sym_init (objfile);
426}
427
428static void
b15cc25c 429debug_sym_read (struct objfile *objfile, symfile_add_flags symfile_flags)
8fb8eb5c 430{
19ba03f4 431 const struct debug_sym_fns_data *debug_data
8c42777c 432 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
433
434 fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n",
b15cc25c 435 objfile_debug_name (objfile), (unsigned) symfile_flags);
8fb8eb5c
DE
436
437 debug_data->real_sf->sym_read (objfile, symfile_flags);
438}
439
440static void
441debug_sym_read_psymbols (struct objfile *objfile)
442{
19ba03f4 443 const struct debug_sym_fns_data *debug_data
8c42777c 444 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
445
446 fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n",
cc485e62 447 objfile_debug_name (objfile));
8fb8eb5c
DE
448
449 debug_data->real_sf->sym_read_psymbols (objfile);
450}
451
452static void
453debug_sym_finish (struct objfile *objfile)
454{
19ba03f4 455 const struct debug_sym_fns_data *debug_data
8c42777c 456 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
457
458 fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n",
cc485e62 459 objfile_debug_name (objfile));
8fb8eb5c
DE
460
461 debug_data->real_sf->sym_finish (objfile);
462}
463
464static void
465debug_sym_offsets (struct objfile *objfile,
37e136b1 466 const section_addr_info &info)
8fb8eb5c 467{
19ba03f4 468 const struct debug_sym_fns_data *debug_data
8c42777c 469 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
470
471 fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n",
cc485e62 472 objfile_debug_name (objfile),
37e136b1 473 host_address_to_string (&info));
8fb8eb5c
DE
474
475 debug_data->real_sf->sym_offsets (objfile, info);
476}
477
62982abd 478static symfile_segment_data_up
8fb8eb5c
DE
479debug_sym_segments (bfd *abfd)
480{
481 /* This API function is annoying, it doesn't take a "this" pointer.
482 Fortunately it is only used in one place where we (re-)lookup the
483 sym_fns table to use. Thus we will never be called. */
484 gdb_assert_not_reached ("debug_sym_segments called");
485}
486
487static void
488debug_sym_read_linetable (struct objfile *objfile)
489{
19ba03f4 490 const struct debug_sym_fns_data *debug_data
8c42777c 491 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
492
493 fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n",
cc485e62 494 objfile_debug_name (objfile));
8fb8eb5c
DE
495
496 debug_data->real_sf->sym_read_linetable (objfile);
497}
498
499static bfd_byte *
500debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf)
501{
19ba03f4 502 const struct debug_sym_fns_data *debug_data
8c42777c 503 = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
504 bfd_byte *retval;
505
506 retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf);
507
508 fprintf_filtered (gdb_stdlog,
509 "sf->sym_relocate (%s, %s, %s) = %s\n",
cc485e62 510 objfile_debug_name (objfile),
8fb8eb5c
DE
511 host_address_to_string (sectp),
512 host_address_to_string (buf),
513 host_address_to_string (retval));
514
515 return retval;
516}
517
518/* Template of debugging version of struct sym_fns.
519 A copy is made, with sym_flavour updated, and a pointer to the real table
520 installed in real_sf, and then a pointer to the copy is installed in the
521 objfile. */
522
523static const struct sym_fns debug_sym_fns =
524{
525 debug_sym_new_init,
526 debug_sym_init,
527 debug_sym_read,
528 debug_sym_read_psymbols,
529 debug_sym_finish,
530 debug_sym_offsets,
531 debug_sym_segments,
532 debug_sym_read_linetable,
533 debug_sym_relocate,
534 &debug_sym_probe_fns,
535 &debug_sym_quick_functions
536};
537\f
8fb8eb5c
DE
538/* Install the debugging versions of the symfile functions for OBJFILE.
539 Do not call this if the debug versions are already installed. */
540
541static void
542install_symfile_debug_logging (struct objfile *objfile)
543{
544 const struct sym_fns *real_sf;
545 struct debug_sym_fns_data *debug_data;
546
547 /* The debug versions should not already be installed. */
548 gdb_assert (!symfile_debug_installed (objfile));
549
550 real_sf = objfile->sf;
551
552 /* Alas we have to preserve NULL entries in REAL_SF. */
8c42777c 553 debug_data = new struct debug_sym_fns_data;
8fb8eb5c
DE
554
555#define COPY_SF_PTR(from, to, name, func) \
556 do { \
557 if ((from)->name) \
558 (to)->debug_sf.name = func; \
559 } while (0)
560
561 COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init);
562 COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init);
563 COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read);
564 COPY_SF_PTR (real_sf, debug_data, sym_read_psymbols,
565 debug_sym_read_psymbols);
566 COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish);
567 COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets);
568 COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments);
569 COPY_SF_PTR (real_sf, debug_data, sym_read_linetable,
570 debug_sym_read_linetable);
571 COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate);
572 if (real_sf->sym_probe_fns)
573 debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns;
574 debug_data->debug_sf.qf = &debug_sym_quick_functions;
575
576#undef COPY_SF_PTR
577
578 debug_data->real_sf = real_sf;
8c42777c 579 symfile_debug_objfile_data_key.set (objfile, debug_data);
8fb8eb5c
DE
580 objfile->sf = &debug_data->debug_sf;
581}
582
583/* Uninstall the debugging versions of the symfile functions for OBJFILE.
584 Do not call this if the debug versions are not installed. */
585
586static void
587uninstall_symfile_debug_logging (struct objfile *objfile)
588{
589 struct debug_sym_fns_data *debug_data;
590
591 /* The debug versions should be currently installed. */
592 gdb_assert (symfile_debug_installed (objfile));
593
8c42777c 594 debug_data = symfile_debug_objfile_data_key.get (objfile);
8fb8eb5c
DE
595
596 objfile->sf = debug_data->real_sf;
8c42777c 597 symfile_debug_objfile_data_key.clear (objfile);
8fb8eb5c
DE
598}
599
600/* Call this function to set OBJFILE->SF.
601 Do not set OBJFILE->SF directly. */
602
603void
604objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf)
605{
606 if (symfile_debug_installed (objfile))
607 {
608 gdb_assert (debug_symfile);
609 /* Remove the current one, and reinstall a new one later. */
610 uninstall_symfile_debug_logging (objfile);
611 }
612
613 /* Assume debug logging is disabled. */
614 objfile->sf = sf;
615
616 /* Turn debug logging on if enabled. */
617 if (debug_symfile)
618 install_symfile_debug_logging (objfile);
619}
620
621static void
eb4c3f4a 622set_debug_symfile (const char *args, int from_tty, struct cmd_list_element *c)
8fb8eb5c 623{
94c93c35 624 for (struct program_space *pspace : program_spaces)
2030c079 625 for (objfile *objfile : pspace->objfiles ())
99d89cde
TT
626 {
627 if (debug_symfile)
628 {
629 if (!symfile_debug_installed (objfile))
630 install_symfile_debug_logging (objfile);
631 }
632 else
633 {
634 if (symfile_debug_installed (objfile))
635 uninstall_symfile_debug_logging (objfile);
636 }
637 }
8fb8eb5c
DE
638}
639
640static void
641show_debug_symfile (struct ui_file *file, int from_tty,
642 struct cmd_list_element *c, const char *value)
643{
644 fprintf_filtered (file, _("Symfile debugging is %s.\n"), value);
645}
646
6c265988 647void _initialize_symfile_debug ();
8fb8eb5c 648void
6c265988 649_initialize_symfile_debug ()
8fb8eb5c 650{
8fb8eb5c
DE
651 add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\
652Set debugging of the symfile functions."), _("\
653Show debugging of the symfile functions."), _("\
654When enabled, all calls to the symfile functions are logged."),
655 set_debug_symfile, show_debug_symfile,
656 &setdebuglist, &showdebuglist);
657
658 /* Note: We don't need a new-objfile observer because debug logging
659 will be installed when objfile init'n calls objfile_set_sym_fns. */
660}
This page took 0.818631 seconds and 4 git commands to generate.