Commit | Line | Data |
---|---|---|
8fb8eb5c DE |
1 | /* Debug logging for the symbol file functions for the GNU debugger, GDB. |
2 | ||
3666a048 | 3 | Copyright (C) 2013-2021 Free Software Foundation, Inc. |
8fb8eb5c DE |
4 | |
5 | Contributed by Cygnus Support, using pieces from other GDB modules. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 3 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | /* Note: Be careful with functions that can throw errors. | |
23 | We want to see a logging message regardless of whether an error was thrown. | |
24 | This typically means printing a message before calling the real function | |
25 | and then if the function returns a result printing a message after it | |
26 | returns. */ | |
27 | ||
28 | #include "defs.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "objfiles.h" | |
76727919 | 31 | #include "observable.h" |
8fb8eb5c DE |
32 | #include "source.h" |
33 | #include "symtab.h" | |
34 | #include "symfile.h" | |
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 | { | |
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 |
48 | static 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. */ |
52 | static bool debug_symfile = false; | |
8fb8eb5c DE |
53 | |
54 | /* Return non-zero if symfile debug logging is installed. */ | |
55 | ||
56 | static int | |
57 | symfile_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 | ||
65 | static const char * | |
66 | debug_symtab_name (struct symtab *symtab) | |
67 | { | |
68 | return symtab_to_filename_for_display (symtab); | |
69 | } | |
70 | \f | |
8fb8eb5c | 71 | |
4d080b46 TT |
72 | /* See objfiles.h. */ |
73 | ||
74 | bool | |
75 | objfile::has_partial_symbols () | |
8fb8eb5c | 76 | { |
4d080b46 | 77 | bool retval = false; |
8fb8eb5c | 78 | |
4d080b46 TT |
79 | /* If we have not read psymbols, but we have a function capable of reading |
80 | them, then that is an indication that they are in fact available. Without | |
81 | this function the symbols may have been already read in but they also may | |
82 | not be present in this objfile. */ | |
e1114590 TT |
83 | for (const auto &iter : qf) |
84 | { | |
85 | if ((flags & OBJF_PSYMTABS_READ) == 0 | |
86 | && iter->can_lazily_read_symbols ()) | |
87 | retval = true; | |
88 | else | |
89 | retval = iter->has_symbols (this); | |
90 | if (retval) | |
91 | break; | |
92 | } | |
8fb8eb5c | 93 | |
4d080b46 TT |
94 | if (debug_symfile) |
95 | fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n", | |
96 | objfile_debug_name (this), retval); | |
8fb8eb5c DE |
97 | |
98 | return retval; | |
99 | } | |
100 | ||
4d080b46 TT |
101 | struct symtab * |
102 | objfile::find_last_source_symtab () | |
8fb8eb5c | 103 | { |
4d080b46 | 104 | struct symtab *retval = nullptr; |
8fb8eb5c | 105 | |
4d080b46 TT |
106 | if (debug_symfile) |
107 | fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n", | |
108 | objfile_debug_name (this)); | |
8fb8eb5c | 109 | |
e1114590 TT |
110 | for (const auto &iter : qf) |
111 | { | |
112 | retval = iter->find_last_source_symtab (this); | |
113 | if (retval != nullptr) | |
114 | break; | |
115 | } | |
8fb8eb5c | 116 | |
4d080b46 TT |
117 | if (debug_symfile) |
118 | fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n", | |
119 | retval ? debug_symtab_name (retval) : "NULL"); | |
8fb8eb5c DE |
120 | |
121 | return retval; | |
122 | } | |
123 | ||
4d080b46 TT |
124 | void |
125 | objfile::forget_cached_source_info () | |
8fb8eb5c | 126 | { |
4d080b46 TT |
127 | if (debug_symfile) |
128 | fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n", | |
129 | objfile_debug_name (this)); | |
8fb8eb5c | 130 | |
e1114590 TT |
131 | for (const auto &iter : qf) |
132 | iter->forget_cached_source_info (this); | |
8fb8eb5c DE |
133 | } |
134 | ||
4d080b46 TT |
135 | bool |
136 | objfile::map_symtabs_matching_filename | |
137 | (const char *name, const char *real_path, | |
14bc53a8 | 138 | gdb::function_view<bool (symtab *)> callback) |
8fb8eb5c | 139 | { |
4d080b46 TT |
140 | if (debug_symfile) |
141 | fprintf_filtered (gdb_stdlog, | |
142 | "qf->map_symtabs_matching_filename (%s, \"%s\", " | |
143 | "\"%s\", %s)\n", | |
144 | objfile_debug_name (this), name, | |
145 | real_path ? real_path : NULL, | |
146 | host_address_to_string (&callback)); | |
8fb8eb5c | 147 | |
4d080b46 | 148 | bool retval = false; |
e1114590 TT |
149 | for (const auto &iter : qf) |
150 | { | |
151 | retval = (iter->map_symtabs_matching_filename | |
152 | (this, name, real_path, callback)); | |
153 | if (retval) | |
154 | break; | |
155 | } | |
8fb8eb5c | 156 | |
4d080b46 TT |
157 | if (debug_symfile) |
158 | fprintf_filtered (gdb_stdlog, | |
159 | "qf->map_symtabs_matching_filename (...) = %d\n", | |
160 | retval); | |
8fb8eb5c DE |
161 | |
162 | return retval; | |
163 | } | |
164 | ||
4d080b46 TT |
165 | struct compunit_symtab * |
166 | objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain) | |
8fb8eb5c | 167 | { |
4d080b46 | 168 | struct compunit_symtab *retval = nullptr; |
8fb8eb5c | 169 | |
4d080b46 TT |
170 | if (debug_symfile) |
171 | fprintf_filtered (gdb_stdlog, | |
172 | "qf->lookup_symbol (%s, %d, \"%s\", %s)\n", | |
173 | objfile_debug_name (this), kind, name, | |
174 | domain_name (domain)); | |
8fb8eb5c | 175 | |
e1114590 TT |
176 | for (const auto &iter : qf) |
177 | { | |
178 | retval = iter->lookup_symbol (this, kind, name, domain); | |
179 | if (retval != nullptr) | |
180 | break; | |
181 | } | |
8fb8eb5c | 182 | |
4d080b46 TT |
183 | if (debug_symfile) |
184 | fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n", | |
185 | retval | |
186 | ? debug_symtab_name (compunit_primary_filetab (retval)) | |
187 | : "NULL"); | |
8fb8eb5c DE |
188 | |
189 | return retval; | |
190 | } | |
191 | ||
4d080b46 | 192 | void |
4829711b | 193 | objfile::print_stats (bool print_bcache) |
8fb8eb5c | 194 | { |
4d080b46 | 195 | if (debug_symfile) |
4829711b TT |
196 | fprintf_filtered (gdb_stdlog, "qf->print_stats (%s, %d)\n", |
197 | objfile_debug_name (this), print_bcache); | |
8fb8eb5c | 198 | |
e1114590 TT |
199 | for (const auto &iter : qf) |
200 | iter->print_stats (this, print_bcache); | |
8fb8eb5c DE |
201 | } |
202 | ||
4d080b46 TT |
203 | void |
204 | objfile::dump () | |
8fb8eb5c | 205 | { |
4d080b46 TT |
206 | if (debug_symfile) |
207 | fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n", | |
208 | objfile_debug_name (this)); | |
8fb8eb5c | 209 | |
e1114590 TT |
210 | for (const auto &iter : qf) |
211 | iter->dump (this); | |
8fb8eb5c DE |
212 | } |
213 | ||
4d080b46 TT |
214 | void |
215 | objfile::expand_symtabs_for_function (const char *func_name) | |
8fb8eb5c | 216 | { |
4d080b46 TT |
217 | if (debug_symfile) |
218 | fprintf_filtered (gdb_stdlog, | |
219 | "qf->expand_symtabs_for_function (%s, \"%s\")\n", | |
220 | objfile_debug_name (this), func_name); | |
8fb8eb5c | 221 | |
e1114590 TT |
222 | for (const auto &iter : qf) |
223 | iter->expand_symtabs_for_function (this, func_name); | |
8fb8eb5c DE |
224 | } |
225 | ||
4d080b46 TT |
226 | void |
227 | objfile::expand_all_symtabs () | |
8fb8eb5c | 228 | { |
4d080b46 TT |
229 | if (debug_symfile) |
230 | fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n", | |
231 | objfile_debug_name (this)); | |
8fb8eb5c | 232 | |
e1114590 TT |
233 | for (const auto &iter : qf) |
234 | iter->expand_all_symtabs (this); | |
8fb8eb5c DE |
235 | } |
236 | ||
4d080b46 TT |
237 | void |
238 | objfile::expand_symtabs_with_fullname (const char *fullname) | |
8fb8eb5c | 239 | { |
4d080b46 TT |
240 | if (debug_symfile) |
241 | fprintf_filtered (gdb_stdlog, | |
242 | "qf->expand_symtabs_with_fullname (%s, \"%s\")\n", | |
243 | objfile_debug_name (this), fullname); | |
8fb8eb5c | 244 | |
e1114590 TT |
245 | for (const auto &iter : qf) |
246 | iter->expand_symtabs_with_fullname (this, fullname); | |
8fb8eb5c DE |
247 | } |
248 | ||
4d080b46 TT |
249 | void |
250 | objfile::map_matching_symbols | |
251 | (const lookup_name_info &name, domain_enum domain, | |
199b4314 TT |
252 | int global, |
253 | gdb::function_view<symbol_found_callback_ftype> callback, | |
199b4314 | 254 | symbol_compare_ftype *ordered_compare) |
8fb8eb5c | 255 | { |
4d080b46 TT |
256 | if (debug_symfile) |
257 | fprintf_filtered (gdb_stdlog, | |
258 | "qf->map_matching_symbols (%s, %s, %d, %s)\n", | |
259 | objfile_debug_name (this), | |
260 | domain_name (domain), global, | |
261 | host_address_to_string (ordered_compare)); | |
8fb8eb5c | 262 | |
e1114590 TT |
263 | for (const auto &iter : qf) |
264 | iter->map_matching_symbols (this, name, domain, global, | |
265 | callback, ordered_compare); | |
8fb8eb5c DE |
266 | } |
267 | ||
df35e626 | 268 | bool |
4d080b46 TT |
269 | objfile::expand_symtabs_matching |
270 | (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher, | |
c1a66c06 | 271 | const lookup_name_info *lookup_name, |
14bc53a8 PA |
272 | gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher, |
273 | gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify, | |
03a8ea51 | 274 | block_search_flags search_flags, |
14bc53a8 | 275 | enum search_domain kind) |
8fb8eb5c | 276 | { |
4d080b46 TT |
277 | if (debug_symfile) |
278 | fprintf_filtered (gdb_stdlog, | |
279 | "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n", | |
280 | objfile_debug_name (this), | |
281 | host_address_to_string (&file_matcher), | |
282 | host_address_to_string (&symbol_matcher), | |
283 | host_address_to_string (&expansion_notify), | |
284 | search_domain_name (kind)); | |
285 | ||
e1114590 | 286 | for (const auto &iter : qf) |
df35e626 TT |
287 | if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name, |
288 | symbol_matcher, expansion_notify, | |
03a8ea51 | 289 | search_flags, kind)) |
df35e626 TT |
290 | return false; |
291 | return true; | |
8fb8eb5c DE |
292 | } |
293 | ||
4d080b46 TT |
294 | struct compunit_symtab * |
295 | objfile::find_pc_sect_compunit_symtab (struct bound_minimal_symbol msymbol, | |
43f3e411 DE |
296 | CORE_ADDR pc, |
297 | struct obj_section *section, | |
298 | int warn_if_readin) | |
8fb8eb5c | 299 | { |
4d080b46 TT |
300 | struct compunit_symtab *retval = nullptr; |
301 | ||
302 | if (debug_symfile) | |
303 | fprintf_filtered (gdb_stdlog, | |
304 | "qf->find_pc_sect_compunit_symtab (%s, %s, %s, %s, %d)\n", | |
305 | objfile_debug_name (this), | |
306 | host_address_to_string (msymbol.minsym), | |
307 | hex_string (pc), | |
308 | host_address_to_string (section), | |
309 | warn_if_readin); | |
310 | ||
e1114590 TT |
311 | for (const auto &iter : qf) |
312 | { | |
313 | retval = iter->find_pc_sect_compunit_symtab (this, msymbol, pc, section, | |
314 | warn_if_readin); | |
315 | if (retval != nullptr) | |
316 | break; | |
317 | } | |
4d080b46 TT |
318 | |
319 | if (debug_symfile) | |
320 | fprintf_filtered (gdb_stdlog, | |
321 | "qf->find_pc_sect_compunit_symtab (...) = %s\n", | |
322 | retval | |
323 | ? debug_symtab_name (compunit_primary_filetab (retval)) | |
324 | : "NULL"); | |
8fb8eb5c DE |
325 | |
326 | return retval; | |
327 | } | |
328 | ||
4d080b46 | 329 | void |
f4655dee TT |
330 | objfile::map_symbol_filenames (gdb::function_view<symbol_filename_ftype> fun, |
331 | bool need_fullname) | |
8fb8eb5c | 332 | { |
4d080b46 TT |
333 | if (debug_symfile) |
334 | fprintf_filtered (gdb_stdlog, | |
f4655dee | 335 | "qf->map_symbol_filenames (%s, ..., %d)\n", |
4d080b46 | 336 | objfile_debug_name (this), |
4d080b46 | 337 | need_fullname); |
8fb8eb5c | 338 | |
e1114590 | 339 | for (const auto &iter : qf) |
f4655dee | 340 | iter->map_symbol_filenames (this, fun, need_fullname); |
8fb8eb5c DE |
341 | } |
342 | ||
4d080b46 TT |
343 | struct compunit_symtab * |
344 | objfile::find_compunit_symtab_by_address (CORE_ADDR address) | |
71a3c369 | 345 | { |
4d080b46 TT |
346 | if (debug_symfile) |
347 | fprintf_filtered (gdb_stdlog, | |
348 | "qf->find_compunit_symtab_by_address (%s, %s)\n", | |
349 | objfile_debug_name (this), | |
350 | hex_string (address)); | |
71a3c369 TT |
351 | |
352 | struct compunit_symtab *result = NULL; | |
e1114590 TT |
353 | for (const auto &iter : qf) |
354 | { | |
355 | result = iter->find_compunit_symtab_by_address (this, address); | |
356 | if (result != nullptr) | |
357 | break; | |
358 | } | |
71a3c369 | 359 | |
4d080b46 TT |
360 | if (debug_symfile) |
361 | fprintf_filtered (gdb_stdlog, | |
362 | "qf->find_compunit_symtab_by_address (...) = %s\n", | |
363 | result | |
364 | ? debug_symtab_name (compunit_primary_filetab (result)) | |
365 | : "NULL"); | |
366 | ||
367 | return result; | |
368 | } | |
369 | ||
370 | enum language | |
371 | objfile::lookup_global_symbol_language (const char *name, | |
372 | domain_enum domain, | |
373 | bool *symbol_found_p) | |
374 | { | |
375 | enum language result = language_unknown; | |
e1114590 | 376 | *symbol_found_p = false; |
4d080b46 | 377 | |
e1114590 TT |
378 | for (const auto &iter : qf) |
379 | { | |
380 | result = iter->lookup_global_symbol_language (this, name, domain, | |
381 | symbol_found_p); | |
382 | if (*symbol_found_p) | |
383 | break; | |
384 | } | |
71a3c369 TT |
385 | |
386 | return result; | |
387 | } | |
388 | ||
d1eef86d TT |
389 | void |
390 | objfile::require_partial_symbols (bool verbose) | |
391 | { | |
392 | if ((flags & OBJF_PSYMTABS_READ) == 0) | |
393 | { | |
394 | flags |= OBJF_PSYMTABS_READ; | |
395 | ||
e1114590 TT |
396 | bool printed = false; |
397 | for (const auto &iter : qf) | |
d1eef86d | 398 | { |
e1114590 TT |
399 | if (iter->can_lazily_read_symbols ()) |
400 | { | |
401 | if (verbose && !printed) | |
402 | { | |
403 | printf_filtered (_("Reading symbols from %s...\n"), | |
404 | objfile_name (this)); | |
405 | printed = true; | |
406 | } | |
407 | iter->read_partial_symbols (this); | |
408 | } | |
d1eef86d | 409 | } |
e1114590 TT |
410 | if (printed && !objfile_has_symbols (this)) |
411 | printf_filtered (_("(No debugging symbols found in %s)\n"), | |
412 | objfile_name (this)); | |
d1eef86d TT |
413 | } |
414 | } | |
415 | ||
8fb8eb5c DE |
416 | \f |
417 | /* Debugging version of struct sym_probe_fns. */ | |
418 | ||
814cf43a | 419 | static const std::vector<std::unique_ptr<probe>> & |
8fb8eb5c DE |
420 | debug_sym_get_probes (struct objfile *objfile) |
421 | { | |
19ba03f4 | 422 | const struct debug_sym_fns_data *debug_data |
8c42777c | 423 | = symfile_debug_objfile_data_key.get (objfile); |
8fb8eb5c | 424 | |
814cf43a | 425 | const std::vector<std::unique_ptr<probe>> &retval |
aaa63a31 | 426 | = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile); |
8fb8eb5c DE |
427 | |
428 | fprintf_filtered (gdb_stdlog, | |
429 | "probes->sym_get_probes (%s) = %s\n", | |
cc485e62 | 430 | objfile_debug_name (objfile), |
aaa63a31 | 431 | host_address_to_string (retval.data ())); |
8fb8eb5c DE |
432 | |
433 | return retval; | |
434 | } | |
435 | ||
8fb8eb5c DE |
436 | static const struct sym_probe_fns debug_sym_probe_fns = |
437 | { | |
438 | debug_sym_get_probes, | |
8fb8eb5c DE |
439 | }; |
440 | \f | |
441 | /* Debugging version of struct sym_fns. */ | |
442 | ||
443 | static void | |
444 | debug_sym_new_init (struct objfile *objfile) | |
445 | { | |
19ba03f4 | 446 | const struct debug_sym_fns_data *debug_data |
8c42777c | 447 | = symfile_debug_objfile_data_key.get (objfile); |
8fb8eb5c DE |
448 | |
449 | fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n", | |
cc485e62 | 450 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
451 | |
452 | debug_data->real_sf->sym_new_init (objfile); | |
453 | } | |
454 | ||
455 | static void | |
456 | debug_sym_init (struct objfile *objfile) | |
457 | { | |
19ba03f4 | 458 | const struct debug_sym_fns_data *debug_data |
8c42777c | 459 | = symfile_debug_objfile_data_key.get (objfile); |
8fb8eb5c DE |
460 | |
461 | fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n", | |
cc485e62 | 462 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
463 | |
464 | debug_data->real_sf->sym_init (objfile); | |
465 | } | |
466 | ||
467 | static void | |
b15cc25c | 468 | debug_sym_read (struct objfile *objfile, symfile_add_flags symfile_flags) |
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_read (%s, 0x%x)\n", | |
b15cc25c | 474 | objfile_debug_name (objfile), (unsigned) symfile_flags); |
8fb8eb5c DE |
475 | |
476 | debug_data->real_sf->sym_read (objfile, symfile_flags); | |
477 | } | |
478 | ||
8fb8eb5c DE |
479 | static void |
480 | debug_sym_finish (struct objfile *objfile) | |
481 | { | |
19ba03f4 | 482 | const struct debug_sym_fns_data *debug_data |
8c42777c | 483 | = symfile_debug_objfile_data_key.get (objfile); |
8fb8eb5c DE |
484 | |
485 | fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n", | |
cc485e62 | 486 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
487 | |
488 | debug_data->real_sf->sym_finish (objfile); | |
489 | } | |
490 | ||
491 | static void | |
492 | debug_sym_offsets (struct objfile *objfile, | |
37e136b1 | 493 | const section_addr_info &info) |
8fb8eb5c | 494 | { |
19ba03f4 | 495 | const struct debug_sym_fns_data *debug_data |
8c42777c | 496 | = symfile_debug_objfile_data_key.get (objfile); |
8fb8eb5c DE |
497 | |
498 | fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n", | |
cc485e62 | 499 | objfile_debug_name (objfile), |
37e136b1 | 500 | host_address_to_string (&info)); |
8fb8eb5c DE |
501 | |
502 | debug_data->real_sf->sym_offsets (objfile, info); | |
503 | } | |
504 | ||
62982abd | 505 | static symfile_segment_data_up |
8fb8eb5c DE |
506 | debug_sym_segments (bfd *abfd) |
507 | { | |
508 | /* This API function is annoying, it doesn't take a "this" pointer. | |
509 | Fortunately it is only used in one place where we (re-)lookup the | |
510 | sym_fns table to use. Thus we will never be called. */ | |
511 | gdb_assert_not_reached ("debug_sym_segments called"); | |
512 | } | |
513 | ||
514 | static void | |
515 | debug_sym_read_linetable (struct objfile *objfile) | |
516 | { | |
19ba03f4 | 517 | const struct debug_sym_fns_data *debug_data |
8c42777c | 518 | = symfile_debug_objfile_data_key.get (objfile); |
8fb8eb5c DE |
519 | |
520 | fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n", | |
cc485e62 | 521 | objfile_debug_name (objfile)); |
8fb8eb5c DE |
522 | |
523 | debug_data->real_sf->sym_read_linetable (objfile); | |
524 | } | |
525 | ||
526 | static bfd_byte * | |
527 | debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf) | |
528 | { | |
19ba03f4 | 529 | const struct debug_sym_fns_data *debug_data |
8c42777c | 530 | = symfile_debug_objfile_data_key.get (objfile); |
8fb8eb5c DE |
531 | bfd_byte *retval; |
532 | ||
533 | retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf); | |
534 | ||
535 | fprintf_filtered (gdb_stdlog, | |
536 | "sf->sym_relocate (%s, %s, %s) = %s\n", | |
cc485e62 | 537 | objfile_debug_name (objfile), |
8fb8eb5c DE |
538 | host_address_to_string (sectp), |
539 | host_address_to_string (buf), | |
540 | host_address_to_string (retval)); | |
541 | ||
542 | return retval; | |
543 | } | |
544 | ||
545 | /* Template of debugging version of struct sym_fns. | |
546 | A copy is made, with sym_flavour updated, and a pointer to the real table | |
547 | installed in real_sf, and then a pointer to the copy is installed in the | |
548 | objfile. */ | |
549 | ||
550 | static const struct sym_fns debug_sym_fns = | |
551 | { | |
552 | debug_sym_new_init, | |
553 | debug_sym_init, | |
554 | debug_sym_read, | |
8fb8eb5c DE |
555 | debug_sym_finish, |
556 | debug_sym_offsets, | |
557 | debug_sym_segments, | |
558 | debug_sym_read_linetable, | |
559 | debug_sym_relocate, | |
560 | &debug_sym_probe_fns, | |
8fb8eb5c DE |
561 | }; |
562 | \f | |
8fb8eb5c DE |
563 | /* Install the debugging versions of the symfile functions for OBJFILE. |
564 | Do not call this if the debug versions are already installed. */ | |
565 | ||
566 | static void | |
567 | install_symfile_debug_logging (struct objfile *objfile) | |
568 | { | |
569 | const struct sym_fns *real_sf; | |
570 | struct debug_sym_fns_data *debug_data; | |
571 | ||
572 | /* The debug versions should not already be installed. */ | |
573 | gdb_assert (!symfile_debug_installed (objfile)); | |
574 | ||
575 | real_sf = objfile->sf; | |
576 | ||
577 | /* Alas we have to preserve NULL entries in REAL_SF. */ | |
8c42777c | 578 | debug_data = new struct debug_sym_fns_data; |
8fb8eb5c DE |
579 | |
580 | #define COPY_SF_PTR(from, to, name, func) \ | |
581 | do { \ | |
582 | if ((from)->name) \ | |
583 | (to)->debug_sf.name = func; \ | |
584 | } while (0) | |
585 | ||
586 | COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init); | |
587 | COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init); | |
588 | COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read); | |
8fb8eb5c DE |
589 | COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish); |
590 | COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets); | |
591 | COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments); | |
592 | COPY_SF_PTR (real_sf, debug_data, sym_read_linetable, | |
593 | debug_sym_read_linetable); | |
594 | COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate); | |
595 | if (real_sf->sym_probe_fns) | |
596 | debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns; | |
8fb8eb5c DE |
597 | |
598 | #undef COPY_SF_PTR | |
599 | ||
600 | debug_data->real_sf = real_sf; | |
8c42777c | 601 | symfile_debug_objfile_data_key.set (objfile, debug_data); |
8fb8eb5c DE |
602 | objfile->sf = &debug_data->debug_sf; |
603 | } | |
604 | ||
605 | /* Uninstall the debugging versions of the symfile functions for OBJFILE. | |
606 | Do not call this if the debug versions are not installed. */ | |
607 | ||
608 | static void | |
609 | uninstall_symfile_debug_logging (struct objfile *objfile) | |
610 | { | |
611 | struct debug_sym_fns_data *debug_data; | |
612 | ||
613 | /* The debug versions should be currently installed. */ | |
614 | gdb_assert (symfile_debug_installed (objfile)); | |
615 | ||
8c42777c | 616 | debug_data = symfile_debug_objfile_data_key.get (objfile); |
8fb8eb5c DE |
617 | |
618 | objfile->sf = debug_data->real_sf; | |
8c42777c | 619 | symfile_debug_objfile_data_key.clear (objfile); |
8fb8eb5c DE |
620 | } |
621 | ||
622 | /* Call this function to set OBJFILE->SF. | |
623 | Do not set OBJFILE->SF directly. */ | |
624 | ||
625 | void | |
626 | objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf) | |
627 | { | |
628 | if (symfile_debug_installed (objfile)) | |
629 | { | |
630 | gdb_assert (debug_symfile); | |
631 | /* Remove the current one, and reinstall a new one later. */ | |
632 | uninstall_symfile_debug_logging (objfile); | |
633 | } | |
634 | ||
635 | /* Assume debug logging is disabled. */ | |
636 | objfile->sf = sf; | |
637 | ||
638 | /* Turn debug logging on if enabled. */ | |
639 | if (debug_symfile) | |
640 | install_symfile_debug_logging (objfile); | |
641 | } | |
642 | ||
643 | static void | |
eb4c3f4a | 644 | set_debug_symfile (const char *args, int from_tty, struct cmd_list_element *c) |
8fb8eb5c | 645 | { |
94c93c35 | 646 | for (struct program_space *pspace : program_spaces) |
2030c079 | 647 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde TT |
648 | { |
649 | if (debug_symfile) | |
650 | { | |
651 | if (!symfile_debug_installed (objfile)) | |
652 | install_symfile_debug_logging (objfile); | |
653 | } | |
654 | else | |
655 | { | |
656 | if (symfile_debug_installed (objfile)) | |
657 | uninstall_symfile_debug_logging (objfile); | |
658 | } | |
659 | } | |
8fb8eb5c DE |
660 | } |
661 | ||
662 | static void | |
663 | show_debug_symfile (struct ui_file *file, int from_tty, | |
664 | struct cmd_list_element *c, const char *value) | |
665 | { | |
666 | fprintf_filtered (file, _("Symfile debugging is %s.\n"), value); | |
667 | } | |
668 | ||
6c265988 | 669 | void _initialize_symfile_debug (); |
8fb8eb5c | 670 | void |
6c265988 | 671 | _initialize_symfile_debug () |
8fb8eb5c | 672 | { |
8fb8eb5c DE |
673 | add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\ |
674 | Set debugging of the symfile functions."), _("\ | |
675 | Show debugging of the symfile functions."), _("\ | |
676 | When enabled, all calls to the symfile functions are logged."), | |
677 | set_debug_symfile, show_debug_symfile, | |
678 | &setdebuglist, &showdebuglist); | |
679 | ||
680 | /* Note: We don't need a new-objfile observer because debug logging | |
681 | will be installed when objfile init'n calls objfile_set_sym_fns. */ | |
682 | } |