GDB (API)
|
00001 /* Debug logging for the symbol file functions for the GNU debugger, GDB. 00002 00003 Copyright (C) 2013 Free Software Foundation, Inc. 00004 00005 Contributed by Cygnus Support, using pieces from other GDB modules. 00006 00007 This file is part of GDB. 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00021 00022 /* Note: Be careful with functions that can throw errors. 00023 We want to see a logging message regardless of whether an error was thrown. 00024 This typically means printing a message before calling the real function 00025 and then if the function returns a result printing a message after it 00026 returns. */ 00027 00028 #include "defs.h" 00029 #include "gdbcmd.h" 00030 #include "objfiles.h" 00031 #include "observer.h" 00032 #include "source.h" 00033 #include "symtab.h" 00034 #include "symfile.h" 00035 00036 /* We need to save a pointer to the real symbol functions. 00037 Plus, the debug versions are malloc'd because we have to NULL out the 00038 ones that are NULL in the real copy. */ 00039 00040 struct debug_sym_fns_data 00041 { 00042 const struct sym_fns *real_sf; 00043 struct sym_fns debug_sf; 00044 }; 00045 00046 /* We need to record a pointer to the real set of functions for each 00047 objfile. */ 00048 static const struct objfile_data *symfile_debug_objfile_data_key; 00049 00050 /* If non-zero all calls to the symfile functions are logged. */ 00051 static int debug_symfile = 0; 00052 00053 /* Return non-zero if symfile debug logging is installed. */ 00054 00055 static int 00056 symfile_debug_installed (struct objfile *objfile) 00057 { 00058 return (objfile->sf != NULL 00059 && objfile_data (objfile, symfile_debug_objfile_data_key) != NULL); 00060 } 00061 00062 /* Utility to return the name to print for OBJFILE. */ 00063 00064 static const char * 00065 debug_objfile_name (const struct objfile *objfile) 00066 { 00067 return lbasename (objfile->original_name); 00068 } 00069 00070 /* Utility return the name to print for SYMTAB. */ 00071 00072 static const char * 00073 debug_symtab_name (struct symtab *symtab) 00074 { 00075 return symtab_to_filename_for_display (symtab); 00076 } 00077 00078 /* Debugging version of struct quick_symbol_functions. */ 00079 00080 static int 00081 debug_qf_has_symbols (struct objfile *objfile) 00082 { 00083 const struct debug_sym_fns_data *debug_data = 00084 objfile_data (objfile, symfile_debug_objfile_data_key); 00085 int retval; 00086 00087 retval = debug_data->real_sf->qf->has_symbols (objfile); 00088 00089 fprintf_filtered (gdb_stdlog, "qf->has_symbols (%s) = %d\n", 00090 debug_objfile_name (objfile), retval); 00091 00092 return retval; 00093 } 00094 00095 static struct symtab * 00096 debug_qf_find_last_source_symtab (struct objfile *objfile) 00097 { 00098 const struct debug_sym_fns_data *debug_data = 00099 objfile_data (objfile, symfile_debug_objfile_data_key); 00100 struct symtab *retval; 00101 00102 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n", 00103 debug_objfile_name (objfile)); 00104 00105 retval = debug_data->real_sf->qf->find_last_source_symtab (objfile); 00106 00107 fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (...) = %s\n", 00108 retval ? debug_symtab_name (retval) : "NULL"); 00109 00110 return retval; 00111 } 00112 00113 static void 00114 debug_qf_forget_cached_source_info (struct objfile *objfile) 00115 { 00116 const struct debug_sym_fns_data *debug_data = 00117 objfile_data (objfile, symfile_debug_objfile_data_key); 00118 00119 fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n", 00120 debug_objfile_name (objfile)); 00121 00122 debug_data->real_sf->qf->forget_cached_source_info (objfile); 00123 } 00124 00125 static int 00126 debug_qf_map_symtabs_matching_filename (struct objfile *objfile, 00127 const char *name, 00128 const char *real_path, 00129 int (*callback) (struct symtab *, 00130 void *), 00131 void *data) 00132 { 00133 const struct debug_sym_fns_data *debug_data = 00134 objfile_data (objfile, symfile_debug_objfile_data_key); 00135 int retval; 00136 00137 fprintf_filtered (gdb_stdlog, 00138 "qf->map_symtabs_matching_filename (%s, \"%s\", \"%s\", %s, %s)\n", 00139 debug_objfile_name (objfile), name, 00140 real_path ? real_path : NULL, 00141 host_address_to_string (callback), 00142 host_address_to_string (data)); 00143 00144 retval = debug_data->real_sf->qf->map_symtabs_matching_filename 00145 (objfile, name, real_path, callback, data); 00146 00147 fprintf_filtered (gdb_stdlog, 00148 "qf->map_symtabs_matching_filename (...) = %d\n", 00149 retval); 00150 00151 return retval; 00152 } 00153 00154 static struct symtab * 00155 debug_qf_lookup_symbol (struct objfile *objfile, int kind, const char *name, 00156 domain_enum domain) 00157 { 00158 const struct debug_sym_fns_data *debug_data = 00159 objfile_data (objfile, symfile_debug_objfile_data_key); 00160 struct symtab *retval; 00161 00162 fprintf_filtered (gdb_stdlog, 00163 "qf->lookup_symbol (%s, %d, \"%s\", %s)\n", 00164 debug_objfile_name (objfile), kind, name, 00165 domain_name (domain)); 00166 00167 retval = debug_data->real_sf->qf->lookup_symbol (objfile, kind, name, 00168 domain); 00169 00170 fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n", 00171 retval ? debug_symtab_name (retval) : "NULL"); 00172 00173 return retval; 00174 } 00175 00176 static void 00177 debug_qf_print_stats (struct objfile *objfile) 00178 { 00179 const struct debug_sym_fns_data *debug_data = 00180 objfile_data (objfile, symfile_debug_objfile_data_key); 00181 00182 fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n", 00183 debug_objfile_name (objfile)); 00184 00185 debug_data->real_sf->qf->print_stats (objfile); 00186 } 00187 00188 static void 00189 debug_qf_dump (struct objfile *objfile) 00190 { 00191 const struct debug_sym_fns_data *debug_data = 00192 objfile_data (objfile, symfile_debug_objfile_data_key); 00193 00194 fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n", 00195 debug_objfile_name (objfile)); 00196 00197 debug_data->real_sf->qf->dump (objfile); 00198 } 00199 00200 static void 00201 debug_qf_relocate (struct objfile *objfile, 00202 const struct section_offsets *new_offsets, 00203 const struct section_offsets *delta) 00204 { 00205 const struct debug_sym_fns_data *debug_data = 00206 objfile_data (objfile, symfile_debug_objfile_data_key); 00207 00208 fprintf_filtered (gdb_stdlog, "qf->relocate (%s, %s, %s)\n", 00209 debug_objfile_name (objfile), 00210 host_address_to_string (new_offsets), 00211 host_address_to_string (delta)); 00212 00213 debug_data->real_sf->qf->relocate (objfile, new_offsets, delta); 00214 } 00215 00216 static void 00217 debug_qf_expand_symtabs_for_function (struct objfile *objfile, 00218 const char *func_name) 00219 { 00220 const struct debug_sym_fns_data *debug_data = 00221 objfile_data (objfile, symfile_debug_objfile_data_key); 00222 00223 fprintf_filtered (gdb_stdlog, 00224 "qf->expand_symtabs_for_function (%s, \"%s\")\n", 00225 debug_objfile_name (objfile), func_name); 00226 00227 debug_data->real_sf->qf->expand_symtabs_for_function (objfile, func_name); 00228 } 00229 00230 static void 00231 debug_qf_expand_all_symtabs (struct objfile *objfile) 00232 { 00233 const struct debug_sym_fns_data *debug_data = 00234 objfile_data (objfile, symfile_debug_objfile_data_key); 00235 00236 fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n", 00237 debug_objfile_name (objfile)); 00238 00239 debug_data->real_sf->qf->expand_all_symtabs (objfile); 00240 } 00241 00242 static void 00243 debug_qf_expand_symtabs_with_fullname (struct objfile *objfile, 00244 const char *fullname) 00245 { 00246 const struct debug_sym_fns_data *debug_data = 00247 objfile_data (objfile, symfile_debug_objfile_data_key); 00248 00249 fprintf_filtered (gdb_stdlog, 00250 "qf->expand_symtabs_with_fullname (%s, \"%s\")\n", 00251 debug_objfile_name (objfile), fullname); 00252 00253 debug_data->real_sf->qf->expand_symtabs_with_fullname (objfile, fullname); 00254 } 00255 00256 static void 00257 debug_qf_map_matching_symbols (struct objfile *objfile, 00258 const char *name, domain_enum namespace, 00259 int global, 00260 int (*callback) (struct block *, 00261 struct symbol *, void *), 00262 void *data, 00263 symbol_compare_ftype *match, 00264 symbol_compare_ftype *ordered_compare) 00265 { 00266 const struct debug_sym_fns_data *debug_data = 00267 objfile_data (objfile, symfile_debug_objfile_data_key); 00268 00269 fprintf_filtered (gdb_stdlog, 00270 "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n", 00271 debug_objfile_name (objfile), name, 00272 domain_name (namespace), global, 00273 host_address_to_string (callback), 00274 host_address_to_string (data), 00275 host_address_to_string (match), 00276 host_address_to_string (ordered_compare)); 00277 00278 debug_data->real_sf->qf->map_matching_symbols (objfile, name, 00279 namespace, global, 00280 callback, data, 00281 match, 00282 ordered_compare); 00283 } 00284 00285 static void 00286 debug_qf_expand_symtabs_matching (struct objfile *objfile, 00287 int (*file_matcher) (const char *, void *, 00288 int basenames), 00289 int (*name_matcher) (const char *, void *), 00290 enum search_domain kind, 00291 void *data) 00292 { 00293 const struct debug_sym_fns_data *debug_data = 00294 objfile_data (objfile, symfile_debug_objfile_data_key); 00295 00296 fprintf_filtered (gdb_stdlog, 00297 "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n", 00298 debug_objfile_name (objfile), 00299 host_address_to_string (file_matcher), 00300 host_address_to_string (name_matcher), 00301 search_domain_name (kind), 00302 host_address_to_string (data)); 00303 00304 debug_data->real_sf->qf->expand_symtabs_matching (objfile, 00305 file_matcher, 00306 name_matcher, 00307 kind, data); 00308 } 00309 00310 static struct symtab * 00311 debug_qf_find_pc_sect_symtab (struct objfile *objfile, 00312 struct minimal_symbol *msymbol, 00313 CORE_ADDR pc, 00314 struct obj_section *section, 00315 int warn_if_readin) 00316 { 00317 const struct debug_sym_fns_data *debug_data = 00318 objfile_data (objfile, symfile_debug_objfile_data_key); 00319 struct symtab *retval; 00320 00321 fprintf_filtered (gdb_stdlog, 00322 "qf->find_pc_sect_symtab (%s, %s, %s, %s, %d)\n", 00323 debug_objfile_name (objfile), 00324 host_address_to_string (msymbol), 00325 hex_string (pc), 00326 host_address_to_string (section), 00327 warn_if_readin); 00328 00329 retval = debug_data->real_sf->qf->find_pc_sect_symtab (objfile, msymbol, 00330 pc, section, 00331 warn_if_readin); 00332 00333 fprintf_filtered (gdb_stdlog, "qf->find_pc_sect_symtab (...) = %s\n", 00334 retval ? debug_symtab_name (retval) : "NULL"); 00335 00336 return retval; 00337 } 00338 00339 static void 00340 debug_qf_map_symbol_filenames (struct objfile *objfile, 00341 symbol_filename_ftype *fun, void *data, 00342 int need_fullname) 00343 { 00344 const struct debug_sym_fns_data *debug_data = 00345 objfile_data (objfile, symfile_debug_objfile_data_key); 00346 fprintf_filtered (gdb_stdlog, 00347 "qf->map_symbol_filenames (%s, %s, %s, %d)\n", 00348 debug_objfile_name (objfile), 00349 host_address_to_string (fun), 00350 host_address_to_string (data), 00351 need_fullname); 00352 00353 debug_data->real_sf->qf->map_symbol_filenames (objfile, fun, data, 00354 need_fullname); 00355 } 00356 00357 static const struct quick_symbol_functions debug_sym_quick_functions = 00358 { 00359 debug_qf_has_symbols, 00360 debug_qf_find_last_source_symtab, 00361 debug_qf_forget_cached_source_info, 00362 debug_qf_map_symtabs_matching_filename, 00363 debug_qf_lookup_symbol, 00364 debug_qf_print_stats, 00365 debug_qf_dump, 00366 debug_qf_relocate, 00367 debug_qf_expand_symtabs_for_function, 00368 debug_qf_expand_all_symtabs, 00369 debug_qf_expand_symtabs_with_fullname, 00370 debug_qf_map_matching_symbols, 00371 debug_qf_expand_symtabs_matching, 00372 debug_qf_find_pc_sect_symtab, 00373 debug_qf_map_symbol_filenames 00374 }; 00375 00376 /* Debugging version of struct sym_probe_fns. */ 00377 00378 static VEC (probe_p) * 00379 debug_sym_get_probes (struct objfile *objfile) 00380 { 00381 const struct debug_sym_fns_data *debug_data = 00382 objfile_data (objfile, symfile_debug_objfile_data_key); 00383 VEC (probe_p) *retval; 00384 00385 retval = debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile); 00386 00387 fprintf_filtered (gdb_stdlog, 00388 "probes->sym_get_probes (%s) = %s\n", 00389 debug_objfile_name (objfile), 00390 host_address_to_string (retval)); 00391 00392 return retval; 00393 } 00394 00395 static unsigned 00396 debug_sym_get_probe_argument_count (struct probe *probe) 00397 { 00398 struct objfile *objfile = probe->objfile; 00399 const struct debug_sym_fns_data *debug_data = 00400 objfile_data (objfile, symfile_debug_objfile_data_key); 00401 unsigned retval; 00402 00403 retval = debug_data->real_sf->sym_probe_fns->sym_get_probe_argument_count 00404 (probe); 00405 00406 fprintf_filtered (gdb_stdlog, 00407 "probes->sym_get_probe_argument_count (%s) = %u\n", 00408 host_address_to_string (probe), retval); 00409 00410 return retval; 00411 } 00412 00413 static int 00414 debug_can_evaluate_probe_arguments (struct probe *probe) 00415 { 00416 struct objfile *objfile = probe->objfile; 00417 const struct debug_sym_fns_data *debug_data = 00418 objfile_data (objfile, symfile_debug_objfile_data_key); 00419 int retval; 00420 00421 retval = debug_data->real_sf->sym_probe_fns->can_evaluate_probe_arguments 00422 (probe); 00423 00424 fprintf_filtered (gdb_stdlog, 00425 "probes->can_evaluate_probe_arguments (%s) = %d\n", 00426 host_address_to_string (probe), retval); 00427 00428 return retval; 00429 } 00430 00431 static struct value * 00432 debug_sym_evaluate_probe_argument (struct probe *probe, unsigned n) 00433 { 00434 struct objfile *objfile = probe->objfile; 00435 const struct debug_sym_fns_data *debug_data = 00436 objfile_data (objfile, symfile_debug_objfile_data_key); 00437 struct value *retval; 00438 00439 fprintf_filtered (gdb_stdlog, 00440 "probes->sym_evaluate_probe_argument (%s, %u)\n", 00441 host_address_to_string (probe), n); 00442 00443 retval = debug_data->real_sf->sym_probe_fns->sym_evaluate_probe_argument 00444 (probe, n); 00445 00446 fprintf_filtered (gdb_stdlog, 00447 "probes->sym_evaluate_probe_argument (...) = %s\n", 00448 host_address_to_string (retval)); 00449 00450 return retval; 00451 } 00452 00453 static void 00454 debug_sym_compile_to_ax (struct probe *probe, struct agent_expr *expr, 00455 struct axs_value *value, unsigned n) 00456 { 00457 struct objfile *objfile = probe->objfile; 00458 const struct debug_sym_fns_data *debug_data = 00459 objfile_data (objfile, symfile_debug_objfile_data_key); 00460 00461 fprintf_filtered (gdb_stdlog, 00462 "probes->sym_compile_to_ax (%s, %s, %s, %u)\n", 00463 host_address_to_string (probe), 00464 host_address_to_string (expr), 00465 host_address_to_string (value), n); 00466 00467 debug_data->real_sf->sym_probe_fns->sym_compile_to_ax 00468 (probe, expr, value, n); 00469 } 00470 00471 static void 00472 debug_sym_relocate_probe (struct objfile *objfile, 00473 const struct section_offsets *new_offsets, 00474 const struct section_offsets *delta) 00475 { 00476 const struct debug_sym_fns_data *debug_data = 00477 objfile_data (objfile, symfile_debug_objfile_data_key); 00478 00479 fprintf_filtered (gdb_stdlog, 00480 "probes->sym_relocate_probe (%s, %s, %s)\n", 00481 debug_objfile_name (objfile), 00482 host_address_to_string (new_offsets), 00483 host_address_to_string (delta)); 00484 00485 debug_data->real_sf->sym_probe_fns->sym_relocate_probe 00486 (objfile, new_offsets, delta); 00487 } 00488 00489 static const struct sym_probe_fns debug_sym_probe_fns = 00490 { 00491 debug_sym_get_probes, 00492 debug_sym_get_probe_argument_count, 00493 debug_can_evaluate_probe_arguments, 00494 debug_sym_evaluate_probe_argument, 00495 debug_sym_compile_to_ax, 00496 debug_sym_relocate_probe 00497 }; 00498 00499 /* Debugging version of struct sym_fns. */ 00500 00501 static void 00502 debug_sym_new_init (struct objfile *objfile) 00503 { 00504 const struct debug_sym_fns_data *debug_data = 00505 objfile_data (objfile, symfile_debug_objfile_data_key); 00506 00507 fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n", 00508 debug_objfile_name (objfile)); 00509 00510 debug_data->real_sf->sym_new_init (objfile); 00511 } 00512 00513 static void 00514 debug_sym_init (struct objfile *objfile) 00515 { 00516 const struct debug_sym_fns_data *debug_data = 00517 objfile_data (objfile, symfile_debug_objfile_data_key); 00518 00519 fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n", 00520 debug_objfile_name (objfile)); 00521 00522 debug_data->real_sf->sym_init (objfile); 00523 } 00524 00525 static void 00526 debug_sym_read (struct objfile *objfile, int symfile_flags) 00527 { 00528 const struct debug_sym_fns_data *debug_data = 00529 objfile_data (objfile, symfile_debug_objfile_data_key); 00530 00531 fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n", 00532 debug_objfile_name (objfile), symfile_flags); 00533 00534 debug_data->real_sf->sym_read (objfile, symfile_flags); 00535 } 00536 00537 static void 00538 debug_sym_read_psymbols (struct objfile *objfile) 00539 { 00540 const struct debug_sym_fns_data *debug_data = 00541 objfile_data (objfile, symfile_debug_objfile_data_key); 00542 00543 fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n", 00544 debug_objfile_name (objfile)); 00545 00546 debug_data->real_sf->sym_read_psymbols (objfile); 00547 } 00548 00549 static void 00550 debug_sym_finish (struct objfile *objfile) 00551 { 00552 const struct debug_sym_fns_data *debug_data = 00553 objfile_data (objfile, symfile_debug_objfile_data_key); 00554 00555 fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n", 00556 debug_objfile_name (objfile)); 00557 00558 debug_data->real_sf->sym_finish (objfile); 00559 } 00560 00561 static void 00562 debug_sym_offsets (struct objfile *objfile, 00563 const struct section_addr_info *info) 00564 { 00565 const struct debug_sym_fns_data *debug_data = 00566 objfile_data (objfile, symfile_debug_objfile_data_key); 00567 00568 fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n", 00569 debug_objfile_name (objfile), 00570 host_address_to_string (info)); 00571 00572 debug_data->real_sf->sym_offsets (objfile, info); 00573 } 00574 00575 static struct symfile_segment_data * 00576 debug_sym_segments (bfd *abfd) 00577 { 00578 /* This API function is annoying, it doesn't take a "this" pointer. 00579 Fortunately it is only used in one place where we (re-)lookup the 00580 sym_fns table to use. Thus we will never be called. */ 00581 gdb_assert_not_reached ("debug_sym_segments called"); 00582 } 00583 00584 static void 00585 debug_sym_read_linetable (struct objfile *objfile) 00586 { 00587 const struct debug_sym_fns_data *debug_data = 00588 objfile_data (objfile, symfile_debug_objfile_data_key); 00589 00590 fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n", 00591 debug_objfile_name (objfile)); 00592 00593 debug_data->real_sf->sym_read_linetable (objfile); 00594 } 00595 00596 static bfd_byte * 00597 debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf) 00598 { 00599 const struct debug_sym_fns_data *debug_data = 00600 objfile_data (objfile, symfile_debug_objfile_data_key); 00601 bfd_byte *retval; 00602 00603 retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf); 00604 00605 fprintf_filtered (gdb_stdlog, 00606 "sf->sym_relocate (%s, %s, %s) = %s\n", 00607 debug_objfile_name (objfile), 00608 host_address_to_string (sectp), 00609 host_address_to_string (buf), 00610 host_address_to_string (retval)); 00611 00612 return retval; 00613 } 00614 00615 /* Template of debugging version of struct sym_fns. 00616 A copy is made, with sym_flavour updated, and a pointer to the real table 00617 installed in real_sf, and then a pointer to the copy is installed in the 00618 objfile. */ 00619 00620 static const struct sym_fns debug_sym_fns = 00621 { 00622 debug_sym_new_init, 00623 debug_sym_init, 00624 debug_sym_read, 00625 debug_sym_read_psymbols, 00626 debug_sym_finish, 00627 debug_sym_offsets, 00628 debug_sym_segments, 00629 debug_sym_read_linetable, 00630 debug_sym_relocate, 00631 &debug_sym_probe_fns, 00632 &debug_sym_quick_functions 00633 }; 00634 00635 /* Free the copy of sym_fns recorded in the registry. */ 00636 00637 static void 00638 symfile_debug_free_objfile (struct objfile *objfile, void *datum) 00639 { 00640 xfree (datum); 00641 } 00642 00643 /* Install the debugging versions of the symfile functions for OBJFILE. 00644 Do not call this if the debug versions are already installed. */ 00645 00646 static void 00647 install_symfile_debug_logging (struct objfile *objfile) 00648 { 00649 const struct sym_fns *real_sf; 00650 struct debug_sym_fns_data *debug_data; 00651 00652 /* The debug versions should not already be installed. */ 00653 gdb_assert (!symfile_debug_installed (objfile)); 00654 00655 real_sf = objfile->sf; 00656 00657 /* Alas we have to preserve NULL entries in REAL_SF. */ 00658 debug_data = XZALLOC (struct debug_sym_fns_data); 00659 00660 #define COPY_SF_PTR(from, to, name, func) \ 00661 do { \ 00662 if ((from)->name) \ 00663 (to)->debug_sf.name = func; \ 00664 } while (0) 00665 00666 COPY_SF_PTR (real_sf, debug_data, sym_new_init, debug_sym_new_init); 00667 COPY_SF_PTR (real_sf, debug_data, sym_init, debug_sym_init); 00668 COPY_SF_PTR (real_sf, debug_data, sym_read, debug_sym_read); 00669 COPY_SF_PTR (real_sf, debug_data, sym_read_psymbols, 00670 debug_sym_read_psymbols); 00671 COPY_SF_PTR (real_sf, debug_data, sym_finish, debug_sym_finish); 00672 COPY_SF_PTR (real_sf, debug_data, sym_offsets, debug_sym_offsets); 00673 COPY_SF_PTR (real_sf, debug_data, sym_segments, debug_sym_segments); 00674 COPY_SF_PTR (real_sf, debug_data, sym_read_linetable, 00675 debug_sym_read_linetable); 00676 COPY_SF_PTR (real_sf, debug_data, sym_relocate, debug_sym_relocate); 00677 if (real_sf->sym_probe_fns) 00678 debug_data->debug_sf.sym_probe_fns = &debug_sym_probe_fns; 00679 debug_data->debug_sf.qf = &debug_sym_quick_functions; 00680 00681 #undef COPY_SF_PTR 00682 00683 debug_data->real_sf = real_sf; 00684 set_objfile_data (objfile, symfile_debug_objfile_data_key, debug_data); 00685 objfile->sf = &debug_data->debug_sf; 00686 } 00687 00688 /* Uninstall the debugging versions of the symfile functions for OBJFILE. 00689 Do not call this if the debug versions are not installed. */ 00690 00691 static void 00692 uninstall_symfile_debug_logging (struct objfile *objfile) 00693 { 00694 struct debug_sym_fns_data *debug_data; 00695 00696 /* The debug versions should be currently installed. */ 00697 gdb_assert (symfile_debug_installed (objfile)); 00698 00699 debug_data = objfile_data (objfile, symfile_debug_objfile_data_key); 00700 00701 objfile->sf = debug_data->real_sf; 00702 xfree (debug_data); 00703 set_objfile_data (objfile, symfile_debug_objfile_data_key, NULL); 00704 } 00705 00706 /* Call this function to set OBJFILE->SF. 00707 Do not set OBJFILE->SF directly. */ 00708 00709 void 00710 objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf) 00711 { 00712 if (symfile_debug_installed (objfile)) 00713 { 00714 gdb_assert (debug_symfile); 00715 /* Remove the current one, and reinstall a new one later. */ 00716 uninstall_symfile_debug_logging (objfile); 00717 } 00718 00719 /* Assume debug logging is disabled. */ 00720 objfile->sf = sf; 00721 00722 /* Turn debug logging on if enabled. */ 00723 if (debug_symfile) 00724 install_symfile_debug_logging (objfile); 00725 } 00726 00727 static void 00728 set_debug_symfile (char *args, int from_tty, struct cmd_list_element *c) 00729 { 00730 struct program_space *pspace; 00731 struct objfile *objfile; 00732 00733 ALL_PSPACES (pspace) 00734 ALL_PSPACE_OBJFILES (pspace, objfile) 00735 { 00736 if (debug_symfile) 00737 { 00738 if (!symfile_debug_installed (objfile)) 00739 install_symfile_debug_logging (objfile); 00740 } 00741 else 00742 { 00743 if (symfile_debug_installed (objfile)) 00744 uninstall_symfile_debug_logging (objfile); 00745 } 00746 } 00747 } 00748 00749 static void 00750 show_debug_symfile (struct ui_file *file, int from_tty, 00751 struct cmd_list_element *c, const char *value) 00752 { 00753 fprintf_filtered (file, _("Symfile debugging is %s.\n"), value); 00754 } 00755 00756 initialize_file_ftype _initialize_symfile_debug; 00757 00758 void 00759 _initialize_symfile_debug (void) 00760 { 00761 symfile_debug_objfile_data_key 00762 = register_objfile_data_with_cleanup (NULL, symfile_debug_free_objfile); 00763 00764 add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\ 00765 Set debugging of the symfile functions."), _("\ 00766 Show debugging of the symfile functions."), _("\ 00767 When enabled, all calls to the symfile functions are logged."), 00768 set_debug_symfile, show_debug_symfile, 00769 &setdebuglist, &showdebuglist); 00770 00771 /* Note: We don't need a new-objfile observer because debug logging 00772 will be installed when objfile init'n calls objfile_set_sym_fns. */ 00773 }