Constify 'la_name' in struct language_defn
[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
3 Copyright (C) 2013 Free Software Foundation, Inc.
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"
31#include "observer.h"
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{
42 const struct sym_fns *real_sf;
43 struct sym_fns debug_sf;
44};
45
46/* We need to record a pointer to the real set of functions for each
47 objfile. */
48static const struct objfile_data *symfile_debug_objfile_data_key;
49
50/* If non-zero all calls to the symfile functions are logged. */
51static int debug_symfile = 0;
52
53/* Return non-zero if symfile debug logging is installed. */
54
55static int
56symfile_debug_installed (struct objfile *objfile)
57{
58 return (objfile->sf != NULL
59 && objfile_data (objfile, symfile_debug_objfile_data_key) != NULL);
60}
61
62/* Utility to return the name to print for OBJFILE. */
63
64static const char *
65debug_objfile_name (const struct objfile *objfile)
66{
67 return lbasename (objfile->original_name);
68}
69
70/* Utility return the name to print for SYMTAB. */
71
72static const char *
73debug_symtab_name (struct symtab *symtab)
74{
75 return symtab_to_filename_for_display (symtab);
76}
77\f
78/* Debugging version of struct quick_symbol_functions. */
79
80static int
81debug_qf_has_symbols (struct objfile *objfile)
82{
83 const struct debug_sym_fns_data *debug_data =
84 objfile_data (objfile, symfile_debug_objfile_data_key);
85 int retval;
86
87 retval = debug_data->real_sf->qf->has_symbols (objfile);
88
89 fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n",
90 debug_objfile_name (objfile), retval);
91
92 return retval;
93}
94
95static struct symtab *
96debug_qf_find_last_source_symtab (struct objfile *objfile)
97{
98 const struct debug_sym_fns_data *debug_data =
99 objfile_data (objfile, symfile_debug_objfile_data_key);
100 struct symtab *retval;
101
102 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
103 debug_objfile_name (objfile));
104
105 retval = debug_data->real_sf->qf->find_last_source_symtab (objfile);
106
107 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n",
108 retval ? debug_symtab_name (retval) : "NULL");
109
110 return retval;
111}
112
113static void
114debug_qf_forget_cached_source_info (struct objfile *objfile)
115{
116 const struct debug_sym_fns_data *debug_data =
117 objfile_data (objfile, symfile_debug_objfile_data_key);
118
119 fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
120 debug_objfile_name (objfile));
121
122 debug_data->real_sf->qf->forget_cached_source_info (objfile);
123}
124
125static int
126debug_qf_map_symtabs_matching_filename (struct objfile *objfile,
127 const char *name,
128 const char *real_path,
129 int (*callback) (struct symtab *,
130 void *),
131 void *data)
132{
133 const struct debug_sym_fns_data *debug_data =
134 objfile_data (objfile, symfile_debug_objfile_data_key);
135 int retval;
136
137 fprintf_filtered (gdb_stdlog,
138 "qf->map_symtabs_matching_filename (%s, \"%s\", \"%s\", %s, %s)\n",
139 debug_objfile_name (objfile), name,
140 real_path ? real_path : NULL,
141 host_address_to_string (callback),
142 host_address_to_string (data));
143
144 retval = debug_data->real_sf->qf->map_symtabs_matching_filename
145 (objfile, name, real_path, callback, data);
146
147 fprintf_filtered (gdb_stdlog,
148 "qf->map_symtabs_matching_filename (...) = %d\n",
149 retval);
150
151 return retval;
152}
153
154static struct symtab *
155debug_qf_lookup_symbol (struct objfile *objfile, int kind, const char *name,
156 domain_enum domain)
157{
158 const struct debug_sym_fns_data *debug_data =
159 objfile_data (objfile, symfile_debug_objfile_data_key);
160 struct symtab *retval;
161
162 fprintf_filtered (gdb_stdlog,
163 "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
164 debug_objfile_name (objfile), kind, name,
165 domain_name (domain));
166
167 retval = debug_data->real_sf->qf->lookup_symbol (objfile, kind, name,
168 domain);
169
170 fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
171 retval ? debug_symtab_name (retval) : "NULL");
172
173 return retval;
174}
175
176static void
177debug_qf_print_stats (struct objfile *objfile)
178{
179 const struct debug_sym_fns_data *debug_data =
180 objfile_data (objfile, symfile_debug_objfile_data_key);
181
182 fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
183 debug_objfile_name (objfile));
184
185 debug_data->real_sf->qf->print_stats (objfile);
186}
187
188static void
189debug_qf_dump (struct objfile *objfile)
190{
191 const struct debug_sym_fns_data *debug_data =
192 objfile_data (objfile, symfile_debug_objfile_data_key);
193
194 fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
195 debug_objfile_name (objfile));
196
197 debug_data->real_sf->qf->dump (objfile);
198}
199
200static void
201debug_qf_relocate (struct objfile *objfile,
202 const struct section_offsets *new_offsets,
203 const struct section_offsets *delta)
204{
205 const struct debug_sym_fns_data *debug_data =
206 objfile_data (objfile, symfile_debug_objfile_data_key);
207
208 fprintf_filtered (gdb_stdlog, "qf->relocate (%s, %s, %s)\n",
209 debug_objfile_name (objfile),
210 host_address_to_string (new_offsets),
211 host_address_to_string (delta));
212
213 debug_data->real_sf->qf->relocate (objfile, new_offsets, delta);
214}
215
216static void
217debug_qf_expand_symtabs_for_function (struct objfile *objfile,
218 const char *func_name)
219{
220 const struct debug_sym_fns_data *debug_data =
221 objfile_data (objfile, symfile_debug_objfile_data_key);
222
223 fprintf_filtered (gdb_stdlog,
224 "qf->expand_symtabs_for_function (%s, \"%s\")\n",
225 debug_objfile_name (objfile), func_name);
226
227 debug_data->real_sf->qf->expand_symtabs_for_function (objfile, func_name);
228}
229
230static void
231debug_qf_expand_all_symtabs (struct objfile *objfile)
232{
233 const struct debug_sym_fns_data *debug_data =
234 objfile_data (objfile, symfile_debug_objfile_data_key);
235
236 fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
237 debug_objfile_name (objfile));
238
239 debug_data->real_sf->qf->expand_all_symtabs (objfile);
240}
241
242static void
243debug_qf_expand_symtabs_with_fullname (struct objfile *objfile,
244 const char *fullname)
245{
246 const struct debug_sym_fns_data *debug_data =
247 objfile_data (objfile, symfile_debug_objfile_data_key);
248
249 fprintf_filtered (gdb_stdlog,
250 "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
251 debug_objfile_name (objfile), fullname);
252
253 debug_data->real_sf->qf->expand_symtabs_with_fullname (objfile, fullname);
254}
255
256static void
257debug_qf_map_matching_symbols (struct objfile *objfile,
258 const char *name, domain_enum namespace,
259 int global,
260 int (*callback) (struct block *,
261 struct symbol *, void *),
262 void *data,
263 symbol_compare_ftype *match,
264 symbol_compare_ftype *ordered_compare)
265{
266 const struct debug_sym_fns_data *debug_data =
267 objfile_data (objfile, symfile_debug_objfile_data_key);
268
269 fprintf_filtered (gdb_stdlog,
270 "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n",
271 debug_objfile_name (objfile), name,
272 domain_name (namespace), global,
273 host_address_to_string (callback),
274 host_address_to_string (data),
275 host_address_to_string (match),
276 host_address_to_string (ordered_compare));
277
278 debug_data->real_sf->qf->map_matching_symbols (objfile, name,
279 namespace, global,
280 callback, data,
281 match,
282 ordered_compare);
283}
284
285static void
286debug_qf_expand_symtabs_matching (struct objfile *objfile,
287 int (*file_matcher) (const char *, void *,
288 int basenames),
289 int (*name_matcher) (const char *, void *),
290 enum search_domain kind,
291 void *data)
292{
293 const struct debug_sym_fns_data *debug_data =
294 objfile_data (objfile, symfile_debug_objfile_data_key);
295
296 fprintf_filtered (gdb_stdlog,
297 "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
298 debug_objfile_name (objfile),
299 host_address_to_string (file_matcher),
300 host_address_to_string (name_matcher),
301 search_domain_name (kind),
302 host_address_to_string (data));
303
304 debug_data->real_sf->qf->expand_symtabs_matching (objfile,
305 file_matcher,
306 name_matcher,
307 kind, data);
308}
309
310static struct symtab *
311debug_qf_find_pc_sect_symtab (struct objfile *objfile,
312 struct minimal_symbol *msymbol,
313 CORE_ADDR pc,
314 struct obj_section *section,
315 int warn_if_readin)
316{
317 const struct debug_sym_fns_data *debug_data =
318 objfile_data (objfile, symfile_debug_objfile_data_key);
319 struct symtab *retval;
320
321 fprintf_filtered (gdb_stdlog,
322 "qf->find_pc_sect_symtab (%s, %s, %s, %s, %d)\n",
323 debug_objfile_name (objfile),
324 host_address_to_string (msymbol),
325 hex_string (pc),
326 host_address_to_string (section),
327 warn_if_readin);
328
329 retval = debug_data->real_sf->qf->find_pc_sect_symtab (objfile, msymbol,
330 pc, section,
331 warn_if_readin);
332
333 fprintf_filtered (gdb_stdlog, "qf->find_pc_sect_symtab (...) = %s\n",
334 retval ? debug_symtab_name (retval) : "NULL");
335
336 return retval;
337}
338
339static void
340debug_qf_map_symbol_filenames (struct objfile *objfile,
341 symbol_filename_ftype *fun, void *data,
342 int need_fullname)
343{
344 const struct debug_sym_fns_data *debug_data =
345 objfile_data (objfile, symfile_debug_objfile_data_key);
346 fprintf_filtered (gdb_stdlog,
347 "qf->map_symbol_filenames (%s, %s, %s, %d)\n",
348 debug_objfile_name (objfile),
349 host_address_to_string (fun),
350 host_address_to_string (data),
351 need_fullname);
352
353 debug_data->real_sf->qf->map_symbol_filenames (objfile, fun, data,
354 need_fullname);
355}
356
357static const struct quick_symbol_functions debug_sym_quick_functions =
358{
359 debug_qf_has_symbols,
360 debug_qf_find_last_source_symtab,
361 debug_qf_forget_cached_source_info,
362 debug_qf_map_symtabs_matching_filename,
363 debug_qf_lookup_symbol,
364 debug_qf_print_stats,
365 debug_qf_dump,
366 debug_qf_relocate,
367 debug_qf_expand_symtabs_for_function,
368 debug_qf_expand_all_symtabs,
369 debug_qf_expand_symtabs_with_fullname,
370 debug_qf_map_matching_symbols,
371 debug_qf_expand_symtabs_matching,
372 debug_qf_find_pc_sect_symtab,
373 debug_qf_map_symbol_filenames
374};
375\f
376/* Debugging version of struct sym_probe_fns. */
377
378static VEC (probe_p) *
379debug_sym_get_probes (struct objfile *objfile)
380{
381 const struct debug_sym_fns_data *debug_data =
382 objfile_data (objfile, symfile_debug_objfile_data_key);
383 VEC (probe_p) *retval;
384
385 retval = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile);
386
387 fprintf_filtered (gdb_stdlog,
388 "probes->sym_get_probes (%s) = %s\n",
389 debug_objfile_name (objfile),
390 host_address_to_string (retval));
391
392 return retval;
393}
394
395static unsigned
396debug_sym_get_probe_argument_count (struct probe *probe)
397{
398 struct objfile *objfile = probe->objfile;
399 const struct debug_sym_fns_data *debug_data =
400 objfile_data (objfile, symfile_debug_objfile_data_key);
401 unsigned retval;
402
403 retval = debug_data->real_sf->sym_probe_fns->sym_get_probe_argument_count
404 (probe);
405
406 fprintf_filtered (gdb_stdlog,
407 "probes->sym_get_probe_argument_count (%s) = %u\n",
408 host_address_to_string (probe), retval);
409
410 return retval;
411}
412
413static int
414debug_can_evaluate_probe_arguments (struct probe *probe)
415{
416 struct objfile *objfile = probe->objfile;
417 const struct debug_sym_fns_data *debug_data =
418 objfile_data (objfile, symfile_debug_objfile_data_key);
419 int retval;
420
421 retval = debug_data->real_sf->sym_probe_fns->can_evaluate_probe_arguments
422 (probe);
423
424 fprintf_filtered (gdb_stdlog,
425 "probes->can_evaluate_probe_arguments (%s) = %d\n",
426 host_address_to_string (probe), retval);
427
428 return retval;
429}
430
431static struct value *
432debug_sym_evaluate_probe_argument (struct probe *probe, unsigned n)
433{
434 struct objfile *objfile = probe->objfile;
435 const struct debug_sym_fns_data *debug_data =
436 objfile_data (objfile, symfile_debug_objfile_data_key);
437 struct value *retval;
438
439 fprintf_filtered (gdb_stdlog,
440 "probes->sym_evaluate_probe_argument (%s, %u)\n",
441 host_address_to_string (probe), n);
442
443 retval = debug_data->real_sf->sym_probe_fns->sym_evaluate_probe_argument
444 (probe, n);
445
446 fprintf_filtered (gdb_stdlog,
447 "probes->sym_evaluate_probe_argument (...) = %s\n",
448 host_address_to_string (retval));
449
450 return retval;
451}
452
453static void
454debug_sym_compile_to_ax (struct probe *probe, struct agent_expr *expr,
455 struct axs_value *value, unsigned n)
456{
457 struct objfile *objfile = probe->objfile;
458 const struct debug_sym_fns_data *debug_data =
459 objfile_data (objfile, symfile_debug_objfile_data_key);
460
461 fprintf_filtered (gdb_stdlog,
462 "probes->sym_compile_to_ax (%s, %s, %s, %u)\n",
463 host_address_to_string (probe),
464 host_address_to_string (expr),
465 host_address_to_string (value), n);
466
467 debug_data->real_sf->sym_probe_fns->sym_compile_to_ax
468 (probe, expr, value, n);
469}
470
471static void
472debug_sym_relocate_probe (struct objfile *objfile,
473 const struct section_offsets *new_offsets,
474 const struct section_offsets *delta)
475{
476 const struct debug_sym_fns_data *debug_data =
477 objfile_data (objfile, symfile_debug_objfile_data_key);
478
479 fprintf_filtered (gdb_stdlog,
480 "probes->sym_relocate_probe (%s, %s, %s)\n",
481 debug_objfile_name (objfile),
482 host_address_to_string (new_offsets),
483 host_address_to_string (delta));
484
485 debug_data->real_sf->sym_probe_fns->sym_relocate_probe
486 (objfile, new_offsets, delta);
487}
488
489static const struct sym_probe_fns debug_sym_probe_fns =
490{
491 debug_sym_get_probes,
492 debug_sym_get_probe_argument_count,
493 debug_can_evaluate_probe_arguments,
494 debug_sym_evaluate_probe_argument,
495 debug_sym_compile_to_ax,
496 debug_sym_relocate_probe
497};
498\f
499/* Debugging version of struct sym_fns. */
500
501static void
502debug_sym_new_init (struct objfile *objfile)
503{
504 const struct debug_sym_fns_data *debug_data =
505 objfile_data (objfile, symfile_debug_objfile_data_key);
506
507 fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n",
508 debug_objfile_name (objfile));
509
510 debug_data->real_sf->sym_new_init (objfile);
511}
512
513static void
514debug_sym_init (struct objfile *objfile)
515{
516 const struct debug_sym_fns_data *debug_data =
517 objfile_data (objfile, symfile_debug_objfile_data_key);
518
519 fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n",
520 debug_objfile_name (objfile));
521
522 debug_data->real_sf->sym_init (objfile);
523}
524
525static void
526debug_sym_read (struct objfile *objfile, int symfile_flags)
527{
528 const struct debug_sym_fns_data *debug_data =
529 objfile_data (objfile, symfile_debug_objfile_data_key);
530
531 fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n",
532 debug_objfile_name (objfile), symfile_flags);
533
534 debug_data->real_sf->sym_read (objfile, symfile_flags);
535}
536
537static void
538debug_sym_read_psymbols (struct objfile *objfile)
539{
540 const struct debug_sym_fns_data *debug_data =
541 objfile_data (objfile, symfile_debug_objfile_data_key);
542
543 fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n",
544 debug_objfile_name (objfile));
545
546 debug_data->real_sf->sym_read_psymbols (objfile);
547}
548
549static void
550debug_sym_finish (struct objfile *objfile)
551{
552 const struct debug_sym_fns_data *debug_data =
553 objfile_data (objfile, symfile_debug_objfile_data_key);
554
555 fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n",
556 debug_objfile_name (objfile));
557
558 debug_data->real_sf->sym_finish (objfile);
559}
560
561static void
562debug_sym_offsets (struct objfile *objfile,
563 const struct section_addr_info *info)
564{
565 const struct debug_sym_fns_data *debug_data =
566 objfile_data (objfile, symfile_debug_objfile_data_key);
567
568 fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n",
569 debug_objfile_name (objfile),
570 host_address_to_string (info));
571
572 debug_data->real_sf->sym_offsets (objfile, info);
573}
574
575static struct symfile_segment_data *
576debug_sym_segments (bfd *abfd)
577{
578 /* This API function is annoying, it doesn't take a "this" pointer.
579 Fortunately it is only used in one place where we (re-)lookup the
580 sym_fns table to use. Thus we will never be called. */
581 gdb_assert_not_reached ("debug_sym_segments called");
582}
583
584static void
585debug_sym_read_linetable (struct objfile *objfile)
586{
587 const struct debug_sym_fns_data *debug_data =
588 objfile_data (objfile, symfile_debug_objfile_data_key);
589
590 fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n",
591 debug_objfile_name (objfile));
592
593 debug_data->real_sf->sym_read_linetable (objfile);
594}
595
596static bfd_byte *
597debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf)
598{
599 const struct debug_sym_fns_data *debug_data =
600 objfile_data (objfile, symfile_debug_objfile_data_key);
601 bfd_byte *retval;
602
603 retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf);
604
605 fprintf_filtered (gdb_stdlog,
606 "sf->sym_relocate (%s, %s, %s) = %s\n",
607 debug_objfile_name (objfile),
608 host_address_to_string (sectp),
609 host_address_to_string (buf),
610 host_address_to_string (retval));
611
612 return retval;
613}
614
615/* Template of debugging version of struct sym_fns.
616 A copy is made, with sym_flavour updated, and a pointer to the real table
617 installed in real_sf, and then a pointer to the copy is installed in the
618 objfile. */
619
620static const struct sym_fns debug_sym_fns =
621{
622 debug_sym_new_init,
623 debug_sym_init,
624 debug_sym_read,
625 debug_sym_read_psymbols,
626 debug_sym_finish,
627 debug_sym_offsets,
628 debug_sym_segments,
629 debug_sym_read_linetable,
630 debug_sym_relocate,
631 &debug_sym_probe_fns,
632 &debug_sym_quick_functions
633};
634\f
635/* Free the copy of sym_fns recorded in the registry. */
636
637static void
638symfile_debug_free_objfile (struct objfile *objfile, void *datum)
639{
640 xfree (datum);
641}
642
643/* Install the debugging versions of the symfile functions for OBJFILE.
644 Do not call this if the debug versions are already installed. */
645
646static void
647install_symfile_debug_logging (struct objfile *objfile)
648{
649 const struct sym_fns *real_sf;
650 struct debug_sym_fns_data *debug_data;
651
652 /* The debug versions should not already be installed. */
653 gdb_assert (!symfile_debug_installed (objfile));
654
655 real_sf = objfile->sf;
656
657 /* Alas we have to preserve NULL entries in REAL_SF. */
658 debug_data = XZALLOC (struct debug_sym_fns_data);
659
660#define COPY_SF_PTR(from, to, name, func) \
661 do { \
662 if ((from)->name) \
663 (to)->debug_sf.name = func; \
664 } while (0)
665
666 COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init);
667 COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init);
668 COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read);
669 COPY_SF_PTR (real_sf, debug_data, sym_read_psymbols,
670 debug_sym_read_psymbols);
671 COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish);
672 COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets);
673 COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments);
674 COPY_SF_PTR (real_sf, debug_data, sym_read_linetable,
675 debug_sym_read_linetable);
676 COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate);
677 if (real_sf->sym_probe_fns)
678 debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns;
679 debug_data->debug_sf.qf = &debug_sym_quick_functions;
680
681#undef COPY_SF_PTR
682
683 debug_data->real_sf = real_sf;
684 set_objfile_data (objfile, symfile_debug_objfile_data_key, debug_data);
685 objfile->sf = &debug_data->debug_sf;
686}
687
688/* Uninstall the debugging versions of the symfile functions for OBJFILE.
689 Do not call this if the debug versions are not installed. */
690
691static void
692uninstall_symfile_debug_logging (struct objfile *objfile)
693{
694 struct debug_sym_fns_data *debug_data;
695
696 /* The debug versions should be currently installed. */
697 gdb_assert (symfile_debug_installed (objfile));
698
699 debug_data = objfile_data (objfile, symfile_debug_objfile_data_key);
700
701 objfile->sf = debug_data->real_sf;
702 xfree (debug_data);
703 set_objfile_data (objfile, symfile_debug_objfile_data_key, NULL);
704}
705
706/* Call this function to set OBJFILE->SF.
707 Do not set OBJFILE->SF directly. */
708
709void
710objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf)
711{
712 if (symfile_debug_installed (objfile))
713 {
714 gdb_assert (debug_symfile);
715 /* Remove the current one, and reinstall a new one later. */
716 uninstall_symfile_debug_logging (objfile);
717 }
718
719 /* Assume debug logging is disabled. */
720 objfile->sf = sf;
721
722 /* Turn debug logging on if enabled. */
723 if (debug_symfile)
724 install_symfile_debug_logging (objfile);
725}
726
727static void
728set_debug_symfile (char *args, int from_tty, struct cmd_list_element *c)
729{
730 struct program_space *pspace;
731 struct objfile *objfile;
732
733 ALL_PSPACES (pspace)
734 ALL_PSPACE_OBJFILES (pspace, objfile)
735 {
736 if (debug_symfile)
737 {
738 if (!symfile_debug_installed (objfile))
739 install_symfile_debug_logging (objfile);
740 }
741 else
742 {
743 if (symfile_debug_installed (objfile))
744 uninstall_symfile_debug_logging (objfile);
745 }
746 }
747}
748
749static void
750show_debug_symfile (struct ui_file *file, int from_tty,
751 struct cmd_list_element *c, const char *value)
752{
753 fprintf_filtered (file, _("Symfile debugging is %s.\n"), value);
754}
755
756initialize_file_ftype _initialize_symfile_debug;
757
758void
759_initialize_symfile_debug (void)
760{
761 symfile_debug_objfile_data_key
762 = register_objfile_data_with_cleanup (NULL, symfile_debug_free_objfile);
763
764 add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\
765Set debugging of the symfile functions."), _("\
766Show debugging of the symfile functions."), _("\
767When enabled, all calls to the symfile functions are logged."),
768 set_debug_symfile, show_debug_symfile,
769 &setdebuglist, &showdebuglist);
770
771 /* Note: We don't need a new-objfile observer because debug logging
772 will be installed when objfile init'n calls objfile_set_sym_fns. */
773}
This page took 0.102461 seconds and 4 git commands to generate.