Commit | Line | Data |
---|---|---|
8fb8eb5c DE |
1 | /* Debug logging for the symbol file functions for the GNU debugger, GDB. |
2 | ||
ecd75fc8 | 3 | Copyright (C) 2013-2014 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" | |
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 | ||
40 | struct 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. */ | |
48 | static const struct objfile_data *symfile_debug_objfile_data_key; | |
49 | ||
50 | /* If non-zero all calls to the symfile functions are logged. */ | |
51 | static int debug_symfile = 0; | |
52 | ||
53 | /* Return non-zero if symfile debug logging is installed. */ | |
54 | ||
55 | static int | |
56 | symfile_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 | ||
64 | static const char * | |
65 | debug_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 | ||
72 | static const char * | |
73 | debug_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 | ||
80 | static int | |
81 | debug_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 | ||
95 | static struct symtab * | |
96 | debug_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 | ||
113 | static void | |
114 | debug_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 | ||
125 | static int | |
126 | debug_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 | ||
154 | static struct symtab * | |
155 | debug_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 | ||
176 | static void | |
177 | debug_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 | ||
188 | static void | |
189 | debug_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 | ||
200 | static void | |
201 | debug_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 | ||
216 | static void | |
217 | debug_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 | ||
230 | static void | |
231 | debug_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 | ||
242 | static void | |
243 | debug_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 | ||
256 | static void | |
257 | debug_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 | ||
285 | static void | |
e86b67d3 JB |
286 | debug_qf_expand_symtabs_matching |
287 | (struct objfile *objfile, | |
288 | expand_symtabs_file_matcher_ftype *file_matcher, | |
289 | expand_symtabs_symbol_matcher_ftype *symbol_matcher, | |
290 | enum search_domain kind, void *data) | |
8fb8eb5c DE |
291 | { |
292 | const struct debug_sym_fns_data *debug_data = | |
293 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
294 | ||
295 | fprintf_filtered (gdb_stdlog, | |
296 | "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n", | |
297 | debug_objfile_name (objfile), | |
298 | host_address_to_string (file_matcher), | |
3f03e7b1 | 299 | host_address_to_string (symbol_matcher), |
8fb8eb5c DE |
300 | search_domain_name (kind), |
301 | host_address_to_string (data)); | |
302 | ||
303 | debug_data->real_sf->qf->expand_symtabs_matching (objfile, | |
304 | file_matcher, | |
3f03e7b1 | 305 | symbol_matcher, |
8fb8eb5c DE |
306 | kind, data); |
307 | } | |
308 | ||
309 | static struct symtab * | |
310 | debug_qf_find_pc_sect_symtab (struct objfile *objfile, | |
311 | struct minimal_symbol *msymbol, | |
312 | CORE_ADDR pc, | |
313 | struct obj_section *section, | |
314 | int warn_if_readin) | |
315 | { | |
316 | const struct debug_sym_fns_data *debug_data = | |
317 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
318 | struct symtab *retval; | |
319 | ||
320 | fprintf_filtered (gdb_stdlog, | |
321 | "qf->find_pc_sect_symtab (%s, %s, %s, %s, %d)\n", | |
322 | debug_objfile_name (objfile), | |
323 | host_address_to_string (msymbol), | |
324 | hex_string (pc), | |
325 | host_address_to_string (section), | |
326 | warn_if_readin); | |
327 | ||
328 | retval = debug_data->real_sf->qf->find_pc_sect_symtab (objfile, msymbol, | |
329 | pc, section, | |
330 | warn_if_readin); | |
331 | ||
332 | fprintf_filtered (gdb_stdlog, "qf->find_pc_sect_symtab (...) = %s\n", | |
333 | retval ? debug_symtab_name (retval) : "NULL"); | |
334 | ||
335 | return retval; | |
336 | } | |
337 | ||
338 | static void | |
339 | debug_qf_map_symbol_filenames (struct objfile *objfile, | |
340 | symbol_filename_ftype *fun, void *data, | |
341 | int need_fullname) | |
342 | { | |
343 | const struct debug_sym_fns_data *debug_data = | |
344 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
345 | fprintf_filtered (gdb_stdlog, | |
346 | "qf->map_symbol_filenames (%s, %s, %s, %d)\n", | |
347 | debug_objfile_name (objfile), | |
348 | host_address_to_string (fun), | |
349 | host_address_to_string (data), | |
350 | need_fullname); | |
351 | ||
352 | debug_data->real_sf->qf->map_symbol_filenames (objfile, fun, data, | |
353 | need_fullname); | |
354 | } | |
355 | ||
356 | static const struct quick_symbol_functions debug_sym_quick_functions = | |
357 | { | |
358 | debug_qf_has_symbols, | |
359 | debug_qf_find_last_source_symtab, | |
360 | debug_qf_forget_cached_source_info, | |
361 | debug_qf_map_symtabs_matching_filename, | |
362 | debug_qf_lookup_symbol, | |
363 | debug_qf_print_stats, | |
364 | debug_qf_dump, | |
365 | debug_qf_relocate, | |
366 | debug_qf_expand_symtabs_for_function, | |
367 | debug_qf_expand_all_symtabs, | |
368 | debug_qf_expand_symtabs_with_fullname, | |
369 | debug_qf_map_matching_symbols, | |
370 | debug_qf_expand_symtabs_matching, | |
371 | debug_qf_find_pc_sect_symtab, | |
372 | debug_qf_map_symbol_filenames | |
373 | }; | |
374 | \f | |
375 | /* Debugging version of struct sym_probe_fns. */ | |
376 | ||
377 | static VEC (probe_p) * | |
378 | debug_sym_get_probes (struct objfile *objfile) | |
379 | { | |
380 | const struct debug_sym_fns_data *debug_data = | |
381 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
382 | VEC (probe_p) *retval; | |
383 | ||
384 | retval = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile); | |
385 | ||
386 | fprintf_filtered (gdb_stdlog, | |
387 | "probes->sym_get_probes (%s) = %s\n", | |
388 | debug_objfile_name (objfile), | |
389 | host_address_to_string (retval)); | |
390 | ||
391 | return retval; | |
392 | } | |
393 | ||
8fb8eb5c DE |
394 | static void |
395 | debug_sym_relocate_probe (struct objfile *objfile, | |
396 | const struct section_offsets *new_offsets, | |
397 | const struct section_offsets *delta) | |
398 | { | |
399 | const struct debug_sym_fns_data *debug_data = | |
400 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
401 | ||
402 | fprintf_filtered (gdb_stdlog, | |
403 | "probes->sym_relocate_probe (%s, %s, %s)\n", | |
404 | debug_objfile_name (objfile), | |
405 | host_address_to_string (new_offsets), | |
406 | host_address_to_string (delta)); | |
407 | ||
408 | debug_data->real_sf->sym_probe_fns->sym_relocate_probe | |
409 | (objfile, new_offsets, delta); | |
410 | } | |
411 | ||
412 | static const struct sym_probe_fns debug_sym_probe_fns = | |
413 | { | |
414 | debug_sym_get_probes, | |
8fb8eb5c DE |
415 | debug_sym_relocate_probe |
416 | }; | |
417 | \f | |
418 | /* Debugging version of struct sym_fns. */ | |
419 | ||
420 | static void | |
421 | debug_sym_new_init (struct objfile *objfile) | |
422 | { | |
423 | const struct debug_sym_fns_data *debug_data = | |
424 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
425 | ||
426 | fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n", | |
427 | debug_objfile_name (objfile)); | |
428 | ||
429 | debug_data->real_sf->sym_new_init (objfile); | |
430 | } | |
431 | ||
432 | static void | |
433 | debug_sym_init (struct objfile *objfile) | |
434 | { | |
435 | const struct debug_sym_fns_data *debug_data = | |
436 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
437 | ||
438 | fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n", | |
439 | debug_objfile_name (objfile)); | |
440 | ||
441 | debug_data->real_sf->sym_init (objfile); | |
442 | } | |
443 | ||
444 | static void | |
445 | debug_sym_read (struct objfile *objfile, int symfile_flags) | |
446 | { | |
447 | const struct debug_sym_fns_data *debug_data = | |
448 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
449 | ||
450 | fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n", | |
451 | debug_objfile_name (objfile), symfile_flags); | |
452 | ||
453 | debug_data->real_sf->sym_read (objfile, symfile_flags); | |
454 | } | |
455 | ||
456 | static void | |
457 | debug_sym_read_psymbols (struct objfile *objfile) | |
458 | { | |
459 | const struct debug_sym_fns_data *debug_data = | |
460 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
461 | ||
462 | fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n", | |
463 | debug_objfile_name (objfile)); | |
464 | ||
465 | debug_data->real_sf->sym_read_psymbols (objfile); | |
466 | } | |
467 | ||
468 | static void | |
469 | debug_sym_finish (struct objfile *objfile) | |
470 | { | |
471 | const struct debug_sym_fns_data *debug_data = | |
472 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
473 | ||
474 | fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n", | |
475 | debug_objfile_name (objfile)); | |
476 | ||
477 | debug_data->real_sf->sym_finish (objfile); | |
478 | } | |
479 | ||
480 | static void | |
481 | debug_sym_offsets (struct objfile *objfile, | |
482 | const struct section_addr_info *info) | |
483 | { | |
484 | const struct debug_sym_fns_data *debug_data = | |
485 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
486 | ||
487 | fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n", | |
488 | debug_objfile_name (objfile), | |
489 | host_address_to_string (info)); | |
490 | ||
491 | debug_data->real_sf->sym_offsets (objfile, info); | |
492 | } | |
493 | ||
494 | static struct symfile_segment_data * | |
495 | debug_sym_segments (bfd *abfd) | |
496 | { | |
497 | /* This API function is annoying, it doesn't take a "this" pointer. | |
498 | Fortunately it is only used in one place where we (re-)lookup the | |
499 | sym_fns table to use. Thus we will never be called. */ | |
500 | gdb_assert_not_reached ("debug_sym_segments called"); | |
501 | } | |
502 | ||
503 | static void | |
504 | debug_sym_read_linetable (struct objfile *objfile) | |
505 | { | |
506 | const struct debug_sym_fns_data *debug_data = | |
507 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
508 | ||
509 | fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n", | |
510 | debug_objfile_name (objfile)); | |
511 | ||
512 | debug_data->real_sf->sym_read_linetable (objfile); | |
513 | } | |
514 | ||
515 | static bfd_byte * | |
516 | debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf) | |
517 | { | |
518 | const struct debug_sym_fns_data *debug_data = | |
519 | objfile_data (objfile, symfile_debug_objfile_data_key); | |
520 | bfd_byte *retval; | |
521 | ||
522 | retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf); | |
523 | ||
524 | fprintf_filtered (gdb_stdlog, | |
525 | "sf->sym_relocate (%s, %s, %s) = %s\n", | |
526 | debug_objfile_name (objfile), | |
527 | host_address_to_string (sectp), | |
528 | host_address_to_string (buf), | |
529 | host_address_to_string (retval)); | |
530 | ||
531 | return retval; | |
532 | } | |
533 | ||
534 | /* Template of debugging version of struct sym_fns. | |
535 | A copy is made, with sym_flavour updated, and a pointer to the real table | |
536 | installed in real_sf, and then a pointer to the copy is installed in the | |
537 | objfile. */ | |
538 | ||
539 | static const struct sym_fns debug_sym_fns = | |
540 | { | |
541 | debug_sym_new_init, | |
542 | debug_sym_init, | |
543 | debug_sym_read, | |
544 | debug_sym_read_psymbols, | |
545 | debug_sym_finish, | |
546 | debug_sym_offsets, | |
547 | debug_sym_segments, | |
548 | debug_sym_read_linetable, | |
549 | debug_sym_relocate, | |
550 | &debug_sym_probe_fns, | |
551 | &debug_sym_quick_functions | |
552 | }; | |
553 | \f | |
554 | /* Free the copy of sym_fns recorded in the registry. */ | |
555 | ||
556 | static void | |
557 | symfile_debug_free_objfile (struct objfile *objfile, void *datum) | |
558 | { | |
559 | xfree (datum); | |
560 | } | |
561 | ||
562 | /* Install the debugging versions of the symfile functions for OBJFILE. | |
563 | Do not call this if the debug versions are already installed. */ | |
564 | ||
565 | static void | |
566 | install_symfile_debug_logging (struct objfile *objfile) | |
567 | { | |
568 | const struct sym_fns *real_sf; | |
569 | struct debug_sym_fns_data *debug_data; | |
570 | ||
571 | /* The debug versions should not already be installed. */ | |
572 | gdb_assert (!symfile_debug_installed (objfile)); | |
573 | ||
574 | real_sf = objfile->sf; | |
575 | ||
576 | /* Alas we have to preserve NULL entries in REAL_SF. */ | |
41bf6aca | 577 | debug_data = XCNEW (struct debug_sym_fns_data); |
8fb8eb5c DE |
578 | |
579 | #define COPY_SF_PTR(from, to, name, func) \ | |
580 | do { \ | |
581 | if ((from)->name) \ | |
582 | (to)->debug_sf.name = func; \ | |
583 | } while (0) | |
584 | ||
585 | COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init); | |
586 | COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init); | |
587 | COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read); | |
588 | COPY_SF_PTR (real_sf, debug_data, sym_read_psymbols, | |
589 | debug_sym_read_psymbols); | |
590 | COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish); | |
591 | COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets); | |
592 | COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments); | |
593 | COPY_SF_PTR (real_sf, debug_data, sym_read_linetable, | |
594 | debug_sym_read_linetable); | |
595 | COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate); | |
596 | if (real_sf->sym_probe_fns) | |
597 | debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns; | |
598 | debug_data->debug_sf.qf = &debug_sym_quick_functions; | |
599 | ||
600 | #undef COPY_SF_PTR | |
601 | ||
602 | debug_data->real_sf = real_sf; | |
603 | set_objfile_data (objfile, symfile_debug_objfile_data_key, debug_data); | |
604 | objfile->sf = &debug_data->debug_sf; | |
605 | } | |
606 | ||
607 | /* Uninstall the debugging versions of the symfile functions for OBJFILE. | |
608 | Do not call this if the debug versions are not installed. */ | |
609 | ||
610 | static void | |
611 | uninstall_symfile_debug_logging (struct objfile *objfile) | |
612 | { | |
613 | struct debug_sym_fns_data *debug_data; | |
614 | ||
615 | /* The debug versions should be currently installed. */ | |
616 | gdb_assert (symfile_debug_installed (objfile)); | |
617 | ||
618 | debug_data = objfile_data (objfile, symfile_debug_objfile_data_key); | |
619 | ||
620 | objfile->sf = debug_data->real_sf; | |
621 | xfree (debug_data); | |
622 | set_objfile_data (objfile, symfile_debug_objfile_data_key, NULL); | |
623 | } | |
624 | ||
625 | /* Call this function to set OBJFILE->SF. | |
626 | Do not set OBJFILE->SF directly. */ | |
627 | ||
628 | void | |
629 | objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf) | |
630 | { | |
631 | if (symfile_debug_installed (objfile)) | |
632 | { | |
633 | gdb_assert (debug_symfile); | |
634 | /* Remove the current one, and reinstall a new one later. */ | |
635 | uninstall_symfile_debug_logging (objfile); | |
636 | } | |
637 | ||
638 | /* Assume debug logging is disabled. */ | |
639 | objfile->sf = sf; | |
640 | ||
641 | /* Turn debug logging on if enabled. */ | |
642 | if (debug_symfile) | |
643 | install_symfile_debug_logging (objfile); | |
644 | } | |
645 | ||
646 | static void | |
647 | set_debug_symfile (char *args, int from_tty, struct cmd_list_element *c) | |
648 | { | |
649 | struct program_space *pspace; | |
650 | struct objfile *objfile; | |
651 | ||
652 | ALL_PSPACES (pspace) | |
653 | ALL_PSPACE_OBJFILES (pspace, objfile) | |
654 | { | |
655 | if (debug_symfile) | |
656 | { | |
657 | if (!symfile_debug_installed (objfile)) | |
658 | install_symfile_debug_logging (objfile); | |
659 | } | |
660 | else | |
661 | { | |
662 | if (symfile_debug_installed (objfile)) | |
663 | uninstall_symfile_debug_logging (objfile); | |
664 | } | |
665 | } | |
666 | } | |
667 | ||
668 | static void | |
669 | show_debug_symfile (struct ui_file *file, int from_tty, | |
670 | struct cmd_list_element *c, const char *value) | |
671 | { | |
672 | fprintf_filtered (file, _("Symfile debugging is %s.\n"), value); | |
673 | } | |
674 | ||
675 | initialize_file_ftype _initialize_symfile_debug; | |
676 | ||
677 | void | |
678 | _initialize_symfile_debug (void) | |
679 | { | |
680 | symfile_debug_objfile_data_key | |
681 | = register_objfile_data_with_cleanup (NULL, symfile_debug_free_objfile); | |
682 | ||
683 | add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\ | |
684 | Set debugging of the symfile functions."), _("\ | |
685 | Show debugging of the symfile functions."), _("\ | |
686 | When enabled, all calls to the symfile functions are logged."), | |
687 | set_debug_symfile, show_debug_symfile, | |
688 | &setdebuglist, &showdebuglist); | |
689 | ||
690 | /* Note: We don't need a new-objfile observer because debug logging | |
691 | will be installed when objfile init'n calls objfile_set_sym_fns. */ | |
692 | } |