Remove minsym termination
[deliverable/binutils-gdb.git] / gdb / objfiles.c
1 /* GDB routines for manipulating objfiles.
2
3 Copyright (C) 1992-2019 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 /* This file contains support routines for creating, manipulating, and
23 destroying objfile structures. */
24
25 #include "defs.h"
26 #include "bfd.h" /* Binary File Description */
27 #include "symtab.h"
28 #include "symfile.h"
29 #include "objfiles.h"
30 #include "gdb-stabs.h"
31 #include "target.h"
32 #include "bcache.h"
33 #include "expression.h"
34 #include "parser-defs.h"
35
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <fcntl.h>
39 #include "gdb_obstack.h"
40 #include "hashtab.h"
41
42 #include "breakpoint.h"
43 #include "block.h"
44 #include "dictionary.h"
45 #include "source.h"
46 #include "addrmap.h"
47 #include "arch-utils.h"
48 #include "exec.h"
49 #include "observable.h"
50 #include "complaints.h"
51 #include "psymtab.h"
52 #include "solist.h"
53 #include "gdb_bfd.h"
54 #include "btrace.h"
55 #include "common/pathstuff.h"
56
57 #include <vector>
58
59 /* Keep a registry of per-objfile data-pointers required by other GDB
60 modules. */
61
62 DEFINE_REGISTRY (objfile, REGISTRY_ACCESS_FIELD)
63
64 /* Externally visible variables that are owned by this module.
65 See declarations in objfile.h for more info. */
66
67 struct objfile_pspace_info
68 {
69 struct obj_section **sections;
70 int num_sections;
71
72 /* Nonzero if object files have been added since the section map
73 was last updated. */
74 int new_objfiles_available;
75
76 /* Nonzero if the section map MUST be updated before use. */
77 int section_map_dirty;
78
79 /* Nonzero if section map updates should be inhibited if possible. */
80 int inhibit_updates;
81 };
82
83 /* Per-program-space data key. */
84 static const struct program_space_data *objfiles_pspace_data;
85
86 static void
87 objfiles_pspace_data_cleanup (struct program_space *pspace, void *arg)
88 {
89 struct objfile_pspace_info *info = (struct objfile_pspace_info *) arg;
90
91 xfree (info->sections);
92 xfree (info);
93 }
94
95 /* Get the current svr4 data. If none is found yet, add it now. This
96 function always returns a valid object. */
97
98 static struct objfile_pspace_info *
99 get_objfile_pspace_data (struct program_space *pspace)
100 {
101 struct objfile_pspace_info *info;
102
103 info = ((struct objfile_pspace_info *)
104 program_space_data (pspace, objfiles_pspace_data));
105 if (info == NULL)
106 {
107 info = XCNEW (struct objfile_pspace_info);
108 set_program_space_data (pspace, objfiles_pspace_data, info);
109 }
110
111 return info;
112 }
113
114 \f
115
116 /* Per-BFD data key. */
117
118 static const struct bfd_data *objfiles_bfd_data;
119
120 /* Create the per-BFD storage object for OBJFILE. If ABFD is not
121 NULL, and it already has a per-BFD storage object, use that.
122 Otherwise, allocate a new per-BFD storage object. If ABFD is not
123 NULL, the object is allocated on the BFD; otherwise it is allocated
124 on OBJFILE's obstack. Note that it is not safe to call this
125 multiple times for a given OBJFILE -- it can only be called when
126 allocating or re-initializing OBJFILE. */
127
128 static struct objfile_per_bfd_storage *
129 get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
130 {
131 struct objfile_per_bfd_storage *storage = NULL;
132
133 if (abfd != NULL)
134 storage = ((struct objfile_per_bfd_storage *)
135 bfd_data (abfd, objfiles_bfd_data));
136
137 if (storage == NULL)
138 {
139 /* If the object requires gdb to do relocations, we simply fall
140 back to not sharing data across users. These cases are rare
141 enough that this seems reasonable. */
142 if (abfd != NULL && !gdb_bfd_requires_relocations (abfd))
143 {
144 storage
145 = ((struct objfile_per_bfd_storage *)
146 bfd_alloc (abfd, sizeof (struct objfile_per_bfd_storage)));
147 /* objfile_per_bfd_storage is not trivially constructible, must
148 call the ctor manually. */
149 storage = new (storage) objfile_per_bfd_storage ();
150 set_bfd_data (abfd, objfiles_bfd_data, storage);
151 }
152 else
153 storage
154 = obstack_new<objfile_per_bfd_storage> (&objfile->objfile_obstack);
155
156 /* Look up the gdbarch associated with the BFD. */
157 if (abfd != NULL)
158 storage->gdbarch = gdbarch_from_bfd (abfd);
159
160 storage->language_of_main = language_unknown;
161 }
162
163 return storage;
164 }
165
166 /* Free STORAGE. */
167
168 static void
169 free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage)
170 {
171 if (storage->demangled_names_hash)
172 htab_delete (storage->demangled_names_hash);
173 storage->~objfile_per_bfd_storage ();
174 }
175
176 /* A wrapper for free_objfile_per_bfd_storage that can be passed as a
177 cleanup function to the BFD registry. */
178
179 static void
180 objfile_bfd_data_free (struct bfd *unused, void *d)
181 {
182 free_objfile_per_bfd_storage ((struct objfile_per_bfd_storage *) d);
183 }
184
185 /* See objfiles.h. */
186
187 void
188 set_objfile_per_bfd (struct objfile *objfile)
189 {
190 objfile->per_bfd = get_objfile_bfd_data (objfile, objfile->obfd);
191 }
192
193 /* Set the objfile's per-BFD notion of the "main" name and
194 language. */
195
196 void
197 set_objfile_main_name (struct objfile *objfile,
198 const char *name, enum language lang)
199 {
200 if (objfile->per_bfd->name_of_main == NULL
201 || strcmp (objfile->per_bfd->name_of_main, name) != 0)
202 objfile->per_bfd->name_of_main
203 = (const char *) obstack_copy0 (&objfile->per_bfd->storage_obstack, name,
204 strlen (name));
205 objfile->per_bfd->language_of_main = lang;
206 }
207
208 /* Helper structure to map blocks to static link properties in hash tables. */
209
210 struct static_link_htab_entry
211 {
212 const struct block *block;
213 const struct dynamic_prop *static_link;
214 };
215
216 /* Return a hash code for struct static_link_htab_entry *P. */
217
218 static hashval_t
219 static_link_htab_entry_hash (const void *p)
220 {
221 const struct static_link_htab_entry *e
222 = (const struct static_link_htab_entry *) p;
223
224 return htab_hash_pointer (e->block);
225 }
226
227 /* Return whether P1 an P2 (pointers to struct static_link_htab_entry) are
228 mappings for the same block. */
229
230 static int
231 static_link_htab_entry_eq (const void *p1, const void *p2)
232 {
233 const struct static_link_htab_entry *e1
234 = (const struct static_link_htab_entry *) p1;
235 const struct static_link_htab_entry *e2
236 = (const struct static_link_htab_entry *) p2;
237
238 return e1->block == e2->block;
239 }
240
241 /* Register STATIC_LINK as the static link for BLOCK, which is part of OBJFILE.
242 Must not be called more than once for each BLOCK. */
243
244 void
245 objfile_register_static_link (struct objfile *objfile,
246 const struct block *block,
247 const struct dynamic_prop *static_link)
248 {
249 void **slot;
250 struct static_link_htab_entry lookup_entry;
251 struct static_link_htab_entry *entry;
252
253 if (objfile->static_links == NULL)
254 objfile->static_links = htab_create_alloc
255 (1, &static_link_htab_entry_hash, static_link_htab_entry_eq, NULL,
256 xcalloc, xfree);
257
258 /* Create a slot for the mapping, make sure it's the first mapping for this
259 block and then create the mapping itself. */
260 lookup_entry.block = block;
261 slot = htab_find_slot (objfile->static_links, &lookup_entry, INSERT);
262 gdb_assert (*slot == NULL);
263
264 entry = XOBNEW (&objfile->objfile_obstack, static_link_htab_entry);
265 entry->block = block;
266 entry->static_link = static_link;
267 *slot = (void *) entry;
268 }
269
270 /* Look for a static link for BLOCK, which is part of OBJFILE. Return NULL if
271 none was found. */
272
273 const struct dynamic_prop *
274 objfile_lookup_static_link (struct objfile *objfile,
275 const struct block *block)
276 {
277 struct static_link_htab_entry *entry;
278 struct static_link_htab_entry lookup_entry;
279
280 if (objfile->static_links == NULL)
281 return NULL;
282 lookup_entry.block = block;
283 entry
284 = (struct static_link_htab_entry *) htab_find (objfile->static_links,
285 &lookup_entry);
286 if (entry == NULL)
287 return NULL;
288
289 gdb_assert (entry->block == block);
290 return entry->static_link;
291 }
292
293 \f
294
295 /* Called via bfd_map_over_sections to build up the section table that
296 the objfile references. The objfile contains pointers to the start
297 of the table (objfile->sections) and to the first location after
298 the end of the table (objfile->sections_end). */
299
300 static void
301 add_to_objfile_sections_full (struct bfd *abfd, struct bfd_section *asect,
302 struct objfile *objfile, int force)
303 {
304 struct obj_section *section;
305
306 if (!force)
307 {
308 flagword aflag;
309
310 aflag = bfd_get_section_flags (abfd, asect);
311 if (!(aflag & SEC_ALLOC))
312 return;
313 }
314
315 section = &objfile->sections[gdb_bfd_section_index (abfd, asect)];
316 section->objfile = objfile;
317 section->the_bfd_section = asect;
318 section->ovly_mapped = 0;
319 }
320
321 static void
322 add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
323 void *objfilep)
324 {
325 add_to_objfile_sections_full (abfd, asect, (struct objfile *) objfilep, 0);
326 }
327
328 /* Builds a section table for OBJFILE.
329
330 Note that the OFFSET and OVLY_MAPPED in each table entry are
331 initialized to zero. */
332
333 void
334 build_objfile_section_table (struct objfile *objfile)
335 {
336 int count = gdb_bfd_count_sections (objfile->obfd);
337
338 objfile->sections = OBSTACK_CALLOC (&objfile->objfile_obstack,
339 count,
340 struct obj_section);
341 objfile->sections_end = (objfile->sections + count);
342 bfd_map_over_sections (objfile->obfd,
343 add_to_objfile_sections, (void *) objfile);
344
345 /* See gdb_bfd_section_index. */
346 add_to_objfile_sections_full (objfile->obfd, bfd_com_section_ptr, objfile, 1);
347 add_to_objfile_sections_full (objfile->obfd, bfd_und_section_ptr, objfile, 1);
348 add_to_objfile_sections_full (objfile->obfd, bfd_abs_section_ptr, objfile, 1);
349 add_to_objfile_sections_full (objfile->obfd, bfd_ind_section_ptr, objfile, 1);
350 }
351
352 /* Given a pointer to an initialized bfd (ABFD) and some flag bits,
353 initialize the new objfile as best we can and link it into the list
354 of all known objfiles.
355
356 NAME should contain original non-canonicalized filename or other
357 identifier as entered by user. If there is no better source use
358 bfd_get_filename (ABFD). NAME may be NULL only if ABFD is NULL.
359 NAME content is copied into returned objfile.
360
361 The FLAGS word contains various bits (OBJF_*) that can be taken as
362 requests for specific operations. Other bits like OBJF_SHARED are
363 simply copied through to the new objfile flags member. */
364
365 objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_)
366 : flags (flags_),
367 pspace (current_program_space),
368 partial_symtabs (new psymtab_storage ()),
369 obfd (abfd)
370 {
371 const char *expanded_name;
372
373 /* We could use obstack_specify_allocation here instead, but
374 gdb_obstack.h specifies the alloc/dealloc functions. */
375 obstack_init (&objfile_obstack);
376
377 objfile_alloc_data (this);
378
379 gdb::unique_xmalloc_ptr<char> name_holder;
380 if (name == NULL)
381 {
382 gdb_assert (abfd == NULL);
383 gdb_assert ((flags & OBJF_NOT_FILENAME) != 0);
384 expanded_name = "<<anonymous objfile>>";
385 }
386 else if ((flags & OBJF_NOT_FILENAME) != 0
387 || is_target_filename (name))
388 expanded_name = name;
389 else
390 {
391 name_holder = gdb_abspath (name);
392 expanded_name = name_holder.get ();
393 }
394 original_name
395 = (char *) obstack_copy0 (&objfile_obstack,
396 expanded_name,
397 strlen (expanded_name));
398
399 /* Update the per-objfile information that comes from the bfd, ensuring
400 that any data that is reference is saved in the per-objfile data
401 region. */
402
403 gdb_bfd_ref (abfd);
404 if (abfd != NULL)
405 {
406 mtime = bfd_get_mtime (abfd);
407
408 /* Build section table. */
409 build_objfile_section_table (this);
410 }
411
412 per_bfd = get_objfile_bfd_data (this, abfd);
413
414 /* Add this file onto the tail of the linked list of other such files. */
415
416 if (object_files == NULL)
417 object_files = this;
418 else
419 {
420 struct objfile *last_one;
421
422 for (last_one = object_files;
423 last_one->next;
424 last_one = last_one->next);
425 last_one->next = this;
426 }
427
428 /* Rebuild section map next time we need it. */
429 get_objfile_pspace_data (pspace)->new_objfiles_available = 1;
430 }
431
432 /* Retrieve the gdbarch associated with OBJFILE. */
433
434 struct gdbarch *
435 get_objfile_arch (const struct objfile *objfile)
436 {
437 return objfile->per_bfd->gdbarch;
438 }
439
440 /* If there is a valid and known entry point, function fills *ENTRY_P with it
441 and returns non-zero; otherwise it returns zero. */
442
443 int
444 entry_point_address_query (CORE_ADDR *entry_p)
445 {
446 if (symfile_objfile == NULL || !symfile_objfile->per_bfd->ei.entry_point_p)
447 return 0;
448
449 *entry_p = (symfile_objfile->per_bfd->ei.entry_point
450 + ANOFFSET (symfile_objfile->section_offsets,
451 symfile_objfile->per_bfd->ei.the_bfd_section_index));
452
453 return 1;
454 }
455
456 /* Get current entry point address. Call error if it is not known. */
457
458 CORE_ADDR
459 entry_point_address (void)
460 {
461 CORE_ADDR retval;
462
463 if (!entry_point_address_query (&retval))
464 error (_("Entry point address is not known."));
465
466 return retval;
467 }
468
469 /* Iterator on PARENT and every separate debug objfile of PARENT.
470 The usage pattern is:
471 for (objfile = parent;
472 objfile;
473 objfile = objfile_separate_debug_iterate (parent, objfile))
474 ...
475 */
476
477 struct objfile *
478 objfile_separate_debug_iterate (const struct objfile *parent,
479 const struct objfile *objfile)
480 {
481 struct objfile *res;
482
483 /* If any, return the first child. */
484 res = objfile->separate_debug_objfile;
485 if (res)
486 return res;
487
488 /* Common case where there is no separate debug objfile. */
489 if (objfile == parent)
490 return NULL;
491
492 /* Return the brother if any. Note that we don't iterate on brothers of
493 the parents. */
494 res = objfile->separate_debug_objfile_link;
495 if (res)
496 return res;
497
498 for (res = objfile->separate_debug_objfile_backlink;
499 res != parent;
500 res = res->separate_debug_objfile_backlink)
501 {
502 gdb_assert (res != NULL);
503 if (res->separate_debug_objfile_link)
504 return res->separate_debug_objfile_link;
505 }
506 return NULL;
507 }
508
509 /* Put one object file before a specified on in the global list.
510 This can be used to make sure an object file is destroyed before
511 another when using objfiles_safe to free all objfiles. */
512 void
513 put_objfile_before (struct objfile *objfile, struct objfile *before_this)
514 {
515 struct objfile **objp;
516
517 unlink_objfile (objfile);
518
519 for (objp = &object_files; *objp != NULL; objp = &((*objp)->next))
520 {
521 if (*objp == before_this)
522 {
523 objfile->next = *objp;
524 *objp = objfile;
525 return;
526 }
527 }
528
529 internal_error (__FILE__, __LINE__,
530 _("put_objfile_before: before objfile not in list"));
531 }
532
533 /* Unlink OBJFILE from the list of known objfiles, if it is found in the
534 list.
535
536 It is not a bug, or error, to call this function if OBJFILE is not known
537 to be in the current list. This is done in the case of mapped objfiles,
538 for example, just to ensure that the mapped objfile doesn't appear twice
539 in the list. Since the list is threaded, linking in a mapped objfile
540 twice would create a circular list.
541
542 If OBJFILE turns out to be in the list, we zap it's NEXT pointer after
543 unlinking it, just to ensure that we have completely severed any linkages
544 between the OBJFILE and the list. */
545
546 void
547 unlink_objfile (struct objfile *objfile)
548 {
549 struct objfile **objpp;
550
551 for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp)->next))
552 {
553 if (*objpp == objfile)
554 {
555 *objpp = (*objpp)->next;
556 objfile->next = NULL;
557 return;
558 }
559 }
560
561 internal_error (__FILE__, __LINE__,
562 _("unlink_objfile: objfile already unlinked"));
563 }
564
565 /* Add OBJFILE as a separate debug objfile of PARENT. */
566
567 void
568 add_separate_debug_objfile (struct objfile *objfile, struct objfile *parent)
569 {
570 gdb_assert (objfile && parent);
571
572 /* Must not be already in a list. */
573 gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
574 gdb_assert (objfile->separate_debug_objfile_link == NULL);
575 gdb_assert (objfile->separate_debug_objfile == NULL);
576 gdb_assert (parent->separate_debug_objfile_backlink == NULL);
577 gdb_assert (parent->separate_debug_objfile_link == NULL);
578
579 objfile->separate_debug_objfile_backlink = parent;
580 objfile->separate_debug_objfile_link = parent->separate_debug_objfile;
581 parent->separate_debug_objfile = objfile;
582
583 /* Put the separate debug object before the normal one, this is so that
584 usage of objfiles_safe will stay safe. */
585 put_objfile_before (objfile, parent);
586 }
587
588 /* Free all separate debug objfile of OBJFILE, but don't free OBJFILE
589 itself. */
590
591 void
592 free_objfile_separate_debug (struct objfile *objfile)
593 {
594 struct objfile *child;
595
596 for (child = objfile->separate_debug_objfile; child;)
597 {
598 struct objfile *next_child = child->separate_debug_objfile_link;
599 delete child;
600 child = next_child;
601 }
602 }
603
604 /* Destroy an objfile and all the symtabs and psymtabs under it. */
605
606 objfile::~objfile ()
607 {
608 /* First notify observers that this objfile is about to be freed. */
609 gdb::observers::free_objfile.notify (this);
610
611 /* Free all separate debug objfiles. */
612 free_objfile_separate_debug (this);
613
614 if (separate_debug_objfile_backlink)
615 {
616 /* We freed the separate debug file, make sure the base objfile
617 doesn't reference it. */
618 struct objfile *child;
619
620 child = separate_debug_objfile_backlink->separate_debug_objfile;
621
622 if (child == this)
623 {
624 /* THIS is the first child. */
625 separate_debug_objfile_backlink->separate_debug_objfile =
626 separate_debug_objfile_link;
627 }
628 else
629 {
630 /* Find THIS in the list. */
631 while (1)
632 {
633 if (child->separate_debug_objfile_link == this)
634 {
635 child->separate_debug_objfile_link =
636 separate_debug_objfile_link;
637 break;
638 }
639 child = child->separate_debug_objfile_link;
640 gdb_assert (child);
641 }
642 }
643 }
644
645 /* Remove any references to this objfile in the global value
646 lists. */
647 preserve_values (this);
648
649 /* It still may reference data modules have associated with the objfile and
650 the symbol file data. */
651 forget_cached_source_info_for_objfile (this);
652
653 breakpoint_free_objfile (this);
654 btrace_free_objfile (this);
655
656 /* First do any symbol file specific actions required when we are
657 finished with a particular symbol file. Note that if the objfile
658 is using reusable symbol information (via mmalloc) then each of
659 these routines is responsible for doing the correct thing, either
660 freeing things which are valid only during this particular gdb
661 execution, or leaving them to be reused during the next one. */
662
663 if (sf != NULL)
664 (*sf->sym_finish) (this);
665
666 /* Discard any data modules have associated with the objfile. The function
667 still may reference obfd. */
668 objfile_free_data (this);
669
670 if (obfd)
671 gdb_bfd_unref (obfd);
672 else
673 free_objfile_per_bfd_storage (per_bfd);
674
675 /* Remove it from the chain of all objfiles. */
676
677 unlink_objfile (this);
678
679 if (this == symfile_objfile)
680 symfile_objfile = NULL;
681
682 /* Before the symbol table code was redone to make it easier to
683 selectively load and remove information particular to a specific
684 linkage unit, gdb used to do these things whenever the monolithic
685 symbol table was blown away. How much still needs to be done
686 is unknown, but we play it safe for now and keep each action until
687 it is shown to be no longer needed. */
688
689 /* Not all our callers call clear_symtab_users (objfile_purge_solibs,
690 for example), so we need to call this here. */
691 clear_pc_function_cache ();
692
693 /* Clear globals which might have pointed into a removed objfile.
694 FIXME: It's not clear which of these are supposed to persist
695 between expressions and which ought to be reset each time. */
696 expression_context_block = NULL;
697 innermost_block.reset ();
698
699 /* Check to see if the current_source_symtab belongs to this objfile,
700 and if so, call clear_current_source_symtab_and_line. */
701
702 {
703 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
704
705 if (cursal.symtab && SYMTAB_OBJFILE (cursal.symtab) == this)
706 clear_current_source_symtab_and_line ();
707 }
708
709 /* Free the obstacks for non-reusable objfiles. */
710 obstack_free (&objfile_obstack, 0);
711
712 /* Rebuild section map next time we need it. */
713 get_objfile_pspace_data (pspace)->section_map_dirty = 1;
714
715 /* Free the map for static links. There's no need to free static link
716 themselves since they were allocated on the objstack. */
717 if (static_links != NULL)
718 htab_delete (static_links);
719 }
720
721 /* Free all the object files at once and clean up their users. */
722
723 void
724 free_all_objfiles (void)
725 {
726 struct so_list *so;
727
728 /* Any objfile referencewould become stale. */
729 for (so = master_so_list (); so; so = so->next)
730 gdb_assert (so->objfile == NULL);
731
732 for (objfile *objfile : current_program_space->objfiles_safe ())
733 delete objfile;
734 clear_symtab_users (0);
735 }
736 \f
737 /* A helper function for objfile_relocate1 that relocates a single
738 symbol. */
739
740 static void
741 relocate_one_symbol (struct symbol *sym, struct objfile *objfile,
742 struct section_offsets *delta)
743 {
744 fixup_symbol_section (sym, objfile);
745
746 /* The RS6000 code from which this was taken skipped
747 any symbols in STRUCT_DOMAIN or UNDEF_DOMAIN.
748 But I'm leaving out that test, on the theory that
749 they can't possibly pass the tests below. */
750 if ((SYMBOL_CLASS (sym) == LOC_LABEL
751 || SYMBOL_CLASS (sym) == LOC_STATIC)
752 && SYMBOL_SECTION (sym) >= 0)
753 {
754 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (delta, SYMBOL_SECTION (sym));
755 }
756 }
757
758 /* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS
759 entries in new_offsets. SEPARATE_DEBUG_OBJFILE is not touched here.
760 Return non-zero iff any change happened. */
761
762 static int
763 objfile_relocate1 (struct objfile *objfile,
764 const struct section_offsets *new_offsets)
765 {
766 struct section_offsets *delta =
767 ((struct section_offsets *)
768 alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)));
769
770 int something_changed = 0;
771
772 for (int i = 0; i < objfile->num_sections; ++i)
773 {
774 delta->offsets[i] =
775 ANOFFSET (new_offsets, i) - ANOFFSET (objfile->section_offsets, i);
776 if (ANOFFSET (delta, i) != 0)
777 something_changed = 1;
778 }
779 if (!something_changed)
780 return 0;
781
782 /* OK, get all the symtabs. */
783 {
784 for (compunit_symtab *cust : objfile->compunits ())
785 {
786 for (symtab *s : compunit_filetabs (cust))
787 {
788 struct linetable *l;
789
790 /* First the line table. */
791 l = SYMTAB_LINETABLE (s);
792 if (l)
793 {
794 for (int i = 0; i < l->nitems; ++i)
795 l->item[i].pc += ANOFFSET (delta,
796 COMPUNIT_BLOCK_LINE_SECTION
797 (cust));
798 }
799 }
800 }
801
802 for (compunit_symtab *cust : objfile->compunits ())
803 {
804 const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (cust);
805 int block_line_section = COMPUNIT_BLOCK_LINE_SECTION (cust);
806
807 if (BLOCKVECTOR_MAP (bv))
808 addrmap_relocate (BLOCKVECTOR_MAP (bv),
809 ANOFFSET (delta, block_line_section));
810
811 for (int i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i)
812 {
813 struct block *b;
814 struct symbol *sym;
815 struct mdict_iterator miter;
816
817 b = BLOCKVECTOR_BLOCK (bv, i);
818 BLOCK_START (b) += ANOFFSET (delta, block_line_section);
819 BLOCK_END (b) += ANOFFSET (delta, block_line_section);
820
821 if (BLOCK_RANGES (b) != nullptr)
822 for (int j = 0; j < BLOCK_NRANGES (b); j++)
823 {
824 BLOCK_RANGE_START (b, j)
825 += ANOFFSET (delta, block_line_section);
826 BLOCK_RANGE_END (b, j) += ANOFFSET (delta,
827 block_line_section);
828 }
829
830 /* We only want to iterate over the local symbols, not any
831 symbols in included symtabs. */
832 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b), miter, sym)
833 {
834 relocate_one_symbol (sym, objfile, delta);
835 }
836 }
837 }
838 }
839
840 /* This stores relocated addresses and so must be cleared. This
841 will cause it to be recreated on demand. */
842 objfile->psymbol_map.clear ();
843
844 /* Relocate isolated symbols. */
845 {
846 struct symbol *iter;
847
848 for (iter = objfile->template_symbols; iter; iter = iter->hash_next)
849 relocate_one_symbol (iter, objfile, delta);
850 }
851
852 {
853 int i;
854
855 for (i = 0; i < objfile->num_sections; ++i)
856 (objfile->section_offsets)->offsets[i] = ANOFFSET (new_offsets, i);
857 }
858
859 /* Rebuild section map next time we need it. */
860 get_objfile_pspace_data (objfile->pspace)->section_map_dirty = 1;
861
862 /* Update the table in exec_ops, used to read memory. */
863 struct obj_section *s;
864 ALL_OBJFILE_OSECTIONS (objfile, s)
865 {
866 int idx = s - objfile->sections;
867
868 exec_set_section_address (bfd_get_filename (objfile->obfd), idx,
869 obj_section_addr (s));
870 }
871
872 /* Data changed. */
873 return 1;
874 }
875
876 /* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS
877 entries in new_offsets. Process also OBJFILE's SEPARATE_DEBUG_OBJFILEs.
878
879 The number and ordering of sections does differ between the two objfiles.
880 Only their names match. Also the file offsets will differ (objfile being
881 possibly prelinked but separate_debug_objfile is probably not prelinked) but
882 the in-memory absolute address as specified by NEW_OFFSETS must match both
883 files. */
884
885 void
886 objfile_relocate (struct objfile *objfile,
887 const struct section_offsets *new_offsets)
888 {
889 struct objfile *debug_objfile;
890 int changed = 0;
891
892 changed |= objfile_relocate1 (objfile, new_offsets);
893
894 for (debug_objfile = objfile->separate_debug_objfile;
895 debug_objfile;
896 debug_objfile = objfile_separate_debug_iterate (objfile, debug_objfile))
897 {
898 section_addr_info objfile_addrs
899 = build_section_addr_info_from_objfile (objfile);
900
901 /* Here OBJFILE_ADDRS contain the correct absolute addresses, the
902 relative ones must be already created according to debug_objfile. */
903
904 addr_info_make_relative (&objfile_addrs, debug_objfile->obfd);
905
906 gdb_assert (debug_objfile->num_sections
907 == gdb_bfd_count_sections (debug_objfile->obfd));
908 std::vector<struct section_offsets>
909 new_debug_offsets (SIZEOF_N_SECTION_OFFSETS (debug_objfile->num_sections));
910 relative_addr_info_to_section_offsets (new_debug_offsets.data (),
911 debug_objfile->num_sections,
912 objfile_addrs);
913
914 changed |= objfile_relocate1 (debug_objfile, new_debug_offsets.data ());
915 }
916
917 /* Relocate breakpoints as necessary, after things are relocated. */
918 if (changed)
919 breakpoint_re_set ();
920 }
921
922 /* Rebase (add to the offsets) OBJFILE by SLIDE. SEPARATE_DEBUG_OBJFILE is
923 not touched here.
924 Return non-zero iff any change happened. */
925
926 static int
927 objfile_rebase1 (struct objfile *objfile, CORE_ADDR slide)
928 {
929 struct section_offsets *new_offsets =
930 ((struct section_offsets *)
931 alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)));
932 int i;
933
934 for (i = 0; i < objfile->num_sections; ++i)
935 new_offsets->offsets[i] = slide;
936
937 return objfile_relocate1 (objfile, new_offsets);
938 }
939
940 /* Rebase (add to the offsets) OBJFILE by SLIDE. Process also OBJFILE's
941 SEPARATE_DEBUG_OBJFILEs. */
942
943 void
944 objfile_rebase (struct objfile *objfile, CORE_ADDR slide)
945 {
946 struct objfile *debug_objfile;
947 int changed = 0;
948
949 changed |= objfile_rebase1 (objfile, slide);
950
951 for (debug_objfile = objfile->separate_debug_objfile;
952 debug_objfile;
953 debug_objfile = objfile_separate_debug_iterate (objfile, debug_objfile))
954 changed |= objfile_rebase1 (debug_objfile, slide);
955
956 /* Relocate breakpoints as necessary, after things are relocated. */
957 if (changed)
958 breakpoint_re_set ();
959 }
960 \f
961 /* Return non-zero if OBJFILE has partial symbols. */
962
963 int
964 objfile_has_partial_symbols (struct objfile *objfile)
965 {
966 if (!objfile->sf)
967 return 0;
968
969 /* If we have not read psymbols, but we have a function capable of reading
970 them, then that is an indication that they are in fact available. Without
971 this function the symbols may have been already read in but they also may
972 not be present in this objfile. */
973 if ((objfile->flags & OBJF_PSYMTABS_READ) == 0
974 && objfile->sf->sym_read_psymbols != NULL)
975 return 1;
976
977 return objfile->sf->qf->has_symbols (objfile);
978 }
979
980 /* Return non-zero if OBJFILE has full symbols. */
981
982 int
983 objfile_has_full_symbols (struct objfile *objfile)
984 {
985 return objfile->compunit_symtabs != NULL;
986 }
987
988 /* Return non-zero if OBJFILE has full or partial symbols, either directly
989 or through a separate debug file. */
990
991 int
992 objfile_has_symbols (struct objfile *objfile)
993 {
994 struct objfile *o;
995
996 for (o = objfile; o; o = objfile_separate_debug_iterate (objfile, o))
997 if (objfile_has_partial_symbols (o) || objfile_has_full_symbols (o))
998 return 1;
999 return 0;
1000 }
1001
1002
1003 /* Many places in gdb want to test just to see if we have any partial
1004 symbols available. This function returns zero if none are currently
1005 available, nonzero otherwise. */
1006
1007 int
1008 have_partial_symbols (void)
1009 {
1010 for (objfile *ofp : current_program_space->objfiles ())
1011 {
1012 if (objfile_has_partial_symbols (ofp))
1013 return 1;
1014 }
1015 return 0;
1016 }
1017
1018 /* Many places in gdb want to test just to see if we have any full
1019 symbols available. This function returns zero if none are currently
1020 available, nonzero otherwise. */
1021
1022 int
1023 have_full_symbols (void)
1024 {
1025 for (objfile *ofp : current_program_space->objfiles ())
1026 {
1027 if (objfile_has_full_symbols (ofp))
1028 return 1;
1029 }
1030 return 0;
1031 }
1032
1033
1034 /* This operations deletes all objfile entries that represent solibs that
1035 weren't explicitly loaded by the user, via e.g., the add-symbol-file
1036 command. */
1037
1038 void
1039 objfile_purge_solibs (void)
1040 {
1041 for (objfile *objf : current_program_space->objfiles_safe ())
1042 {
1043 /* We assume that the solib package has been purged already, or will
1044 be soon. */
1045
1046 if (!(objf->flags & OBJF_USERLOADED) && (objf->flags & OBJF_SHARED))
1047 delete objf;
1048 }
1049 }
1050
1051
1052 /* Many places in gdb want to test just to see if we have any minimal
1053 symbols available. This function returns zero if none are currently
1054 available, nonzero otherwise. */
1055
1056 int
1057 have_minimal_symbols (void)
1058 {
1059 for (objfile *ofp : current_program_space->objfiles ())
1060 {
1061 if (ofp->per_bfd->minimal_symbol_count > 0)
1062 {
1063 return 1;
1064 }
1065 }
1066 return 0;
1067 }
1068
1069 /* Qsort comparison function. */
1070
1071 static int
1072 qsort_cmp (const void *a, const void *b)
1073 {
1074 const struct obj_section *sect1 = *(const struct obj_section **) a;
1075 const struct obj_section *sect2 = *(const struct obj_section **) b;
1076 const CORE_ADDR sect1_addr = obj_section_addr (sect1);
1077 const CORE_ADDR sect2_addr = obj_section_addr (sect2);
1078
1079 if (sect1_addr < sect2_addr)
1080 return -1;
1081 else if (sect1_addr > sect2_addr)
1082 return 1;
1083 else
1084 {
1085 /* Sections are at the same address. This could happen if
1086 A) we have an objfile and a separate debuginfo.
1087 B) we are confused, and have added sections without proper relocation,
1088 or something like that. */
1089
1090 const struct objfile *const objfile1 = sect1->objfile;
1091 const struct objfile *const objfile2 = sect2->objfile;
1092
1093 if (objfile1->separate_debug_objfile == objfile2
1094 || objfile2->separate_debug_objfile == objfile1)
1095 {
1096 /* Case A. The ordering doesn't matter: separate debuginfo files
1097 will be filtered out later. */
1098
1099 return 0;
1100 }
1101
1102 /* Case B. Maintain stable sort order, so bugs in GDB are easier to
1103 triage. This section could be slow (since we iterate over all
1104 objfiles in each call to qsort_cmp), but this shouldn't happen
1105 very often (GDB is already in a confused state; one hopes this
1106 doesn't happen at all). If you discover that significant time is
1107 spent in the loops below, do 'set complaints 100' and examine the
1108 resulting complaints. */
1109
1110 if (objfile1 == objfile2)
1111 {
1112 /* Both sections came from the same objfile. We are really confused.
1113 Sort on sequence order of sections within the objfile. */
1114
1115 const struct obj_section *osect;
1116
1117 ALL_OBJFILE_OSECTIONS (objfile1, osect)
1118 if (osect == sect1)
1119 return -1;
1120 else if (osect == sect2)
1121 return 1;
1122
1123 /* We should have found one of the sections before getting here. */
1124 gdb_assert_not_reached ("section not found");
1125 }
1126 else
1127 {
1128 /* Sort on sequence number of the objfile in the chain. */
1129
1130 for (objfile *objfile : current_program_space->objfiles ())
1131 if (objfile == objfile1)
1132 return -1;
1133 else if (objfile == objfile2)
1134 return 1;
1135
1136 /* We should have found one of the objfiles before getting here. */
1137 gdb_assert_not_reached ("objfile not found");
1138 }
1139 }
1140
1141 /* Unreachable. */
1142 gdb_assert_not_reached ("unexpected code path");
1143 return 0;
1144 }
1145
1146 /* Select "better" obj_section to keep. We prefer the one that came from
1147 the real object, rather than the one from separate debuginfo.
1148 Most of the time the two sections are exactly identical, but with
1149 prelinking the .rel.dyn section in the real object may have different
1150 size. */
1151
1152 static struct obj_section *
1153 preferred_obj_section (struct obj_section *a, struct obj_section *b)
1154 {
1155 gdb_assert (obj_section_addr (a) == obj_section_addr (b));
1156 gdb_assert ((a->objfile->separate_debug_objfile == b->objfile)
1157 || (b->objfile->separate_debug_objfile == a->objfile));
1158 gdb_assert ((a->objfile->separate_debug_objfile_backlink == b->objfile)
1159 || (b->objfile->separate_debug_objfile_backlink == a->objfile));
1160
1161 if (a->objfile->separate_debug_objfile != NULL)
1162 return a;
1163 return b;
1164 }
1165
1166 /* Return 1 if SECTION should be inserted into the section map.
1167 We want to insert only non-overlay and non-TLS section. */
1168
1169 static int
1170 insert_section_p (const struct bfd *abfd,
1171 const struct bfd_section *section)
1172 {
1173 const bfd_vma lma = bfd_section_lma (abfd, section);
1174
1175 if (overlay_debugging && lma != 0 && lma != bfd_section_vma (abfd, section)
1176 && (bfd_get_file_flags (abfd) & BFD_IN_MEMORY) == 0)
1177 /* This is an overlay section. IN_MEMORY check is needed to avoid
1178 discarding sections from the "system supplied DSO" (aka vdso)
1179 on some Linux systems (e.g. Fedora 11). */
1180 return 0;
1181 if ((bfd_get_section_flags (abfd, section) & SEC_THREAD_LOCAL) != 0)
1182 /* This is a TLS section. */
1183 return 0;
1184
1185 return 1;
1186 }
1187
1188 /* Filter out overlapping sections where one section came from the real
1189 objfile, and the other from a separate debuginfo file.
1190 Return the size of table after redundant sections have been eliminated. */
1191
1192 static int
1193 filter_debuginfo_sections (struct obj_section **map, int map_size)
1194 {
1195 int i, j;
1196
1197 for (i = 0, j = 0; i < map_size - 1; i++)
1198 {
1199 struct obj_section *const sect1 = map[i];
1200 struct obj_section *const sect2 = map[i + 1];
1201 const struct objfile *const objfile1 = sect1->objfile;
1202 const struct objfile *const objfile2 = sect2->objfile;
1203 const CORE_ADDR sect1_addr = obj_section_addr (sect1);
1204 const CORE_ADDR sect2_addr = obj_section_addr (sect2);
1205
1206 if (sect1_addr == sect2_addr
1207 && (objfile1->separate_debug_objfile == objfile2
1208 || objfile2->separate_debug_objfile == objfile1))
1209 {
1210 map[j++] = preferred_obj_section (sect1, sect2);
1211 ++i;
1212 }
1213 else
1214 map[j++] = sect1;
1215 }
1216
1217 if (i < map_size)
1218 {
1219 gdb_assert (i == map_size - 1);
1220 map[j++] = map[i];
1221 }
1222
1223 /* The map should not have shrunk to less than half the original size. */
1224 gdb_assert (map_size / 2 <= j);
1225
1226 return j;
1227 }
1228
1229 /* Filter out overlapping sections, issuing a warning if any are found.
1230 Overlapping sections could really be overlay sections which we didn't
1231 classify as such in insert_section_p, or we could be dealing with a
1232 corrupt binary. */
1233
1234 static int
1235 filter_overlapping_sections (struct obj_section **map, int map_size)
1236 {
1237 int i, j;
1238
1239 for (i = 0, j = 0; i < map_size - 1; )
1240 {
1241 int k;
1242
1243 map[j++] = map[i];
1244 for (k = i + 1; k < map_size; k++)
1245 {
1246 struct obj_section *const sect1 = map[i];
1247 struct obj_section *const sect2 = map[k];
1248 const CORE_ADDR sect1_addr = obj_section_addr (sect1);
1249 const CORE_ADDR sect2_addr = obj_section_addr (sect2);
1250 const CORE_ADDR sect1_endaddr = obj_section_endaddr (sect1);
1251
1252 gdb_assert (sect1_addr <= sect2_addr);
1253
1254 if (sect1_endaddr <= sect2_addr)
1255 break;
1256 else
1257 {
1258 /* We have an overlap. Report it. */
1259
1260 struct objfile *const objf1 = sect1->objfile;
1261 struct objfile *const objf2 = sect2->objfile;
1262
1263 const struct bfd_section *const bfds1 = sect1->the_bfd_section;
1264 const struct bfd_section *const bfds2 = sect2->the_bfd_section;
1265
1266 const CORE_ADDR sect2_endaddr = obj_section_endaddr (sect2);
1267
1268 struct gdbarch *const gdbarch = get_objfile_arch (objf1);
1269
1270 complaint (_("unexpected overlap between:\n"
1271 " (A) section `%s' from `%s' [%s, %s)\n"
1272 " (B) section `%s' from `%s' [%s, %s).\n"
1273 "Will ignore section B"),
1274 bfd_section_name (abfd1, bfds1), objfile_name (objf1),
1275 paddress (gdbarch, sect1_addr),
1276 paddress (gdbarch, sect1_endaddr),
1277 bfd_section_name (abfd2, bfds2), objfile_name (objf2),
1278 paddress (gdbarch, sect2_addr),
1279 paddress (gdbarch, sect2_endaddr));
1280 }
1281 }
1282 i = k;
1283 }
1284
1285 if (i < map_size)
1286 {
1287 gdb_assert (i == map_size - 1);
1288 map[j++] = map[i];
1289 }
1290
1291 return j;
1292 }
1293
1294
1295 /* Update PMAP, PMAP_SIZE with sections from all objfiles, excluding any
1296 TLS, overlay and overlapping sections. */
1297
1298 static void
1299 update_section_map (struct program_space *pspace,
1300 struct obj_section ***pmap, int *pmap_size)
1301 {
1302 struct objfile_pspace_info *pspace_info;
1303 int alloc_size, map_size, i;
1304 struct obj_section *s, **map;
1305
1306 pspace_info = get_objfile_pspace_data (pspace);
1307 gdb_assert (pspace_info->section_map_dirty != 0
1308 || pspace_info->new_objfiles_available != 0);
1309
1310 map = *pmap;
1311 xfree (map);
1312
1313 alloc_size = 0;
1314 for (objfile *objfile : pspace->objfiles ())
1315 ALL_OBJFILE_OSECTIONS (objfile, s)
1316 if (insert_section_p (objfile->obfd, s->the_bfd_section))
1317 alloc_size += 1;
1318
1319 /* This happens on detach/attach (e.g. in gdb.base/attach.exp). */
1320 if (alloc_size == 0)
1321 {
1322 *pmap = NULL;
1323 *pmap_size = 0;
1324 return;
1325 }
1326
1327 map = XNEWVEC (struct obj_section *, alloc_size);
1328
1329 i = 0;
1330 for (objfile *objfile : pspace->objfiles ())
1331 ALL_OBJFILE_OSECTIONS (objfile, s)
1332 if (insert_section_p (objfile->obfd, s->the_bfd_section))
1333 map[i++] = s;
1334
1335 qsort (map, alloc_size, sizeof (*map), qsort_cmp);
1336 map_size = filter_debuginfo_sections(map, alloc_size);
1337 map_size = filter_overlapping_sections(map, map_size);
1338
1339 if (map_size < alloc_size)
1340 /* Some sections were eliminated. Trim excess space. */
1341 map = XRESIZEVEC (struct obj_section *, map, map_size);
1342 else
1343 gdb_assert (alloc_size == map_size);
1344
1345 *pmap = map;
1346 *pmap_size = map_size;
1347 }
1348
1349 /* Bsearch comparison function. */
1350
1351 static int
1352 bsearch_cmp (const void *key, const void *elt)
1353 {
1354 const CORE_ADDR pc = *(CORE_ADDR *) key;
1355 const struct obj_section *section = *(const struct obj_section **) elt;
1356
1357 if (pc < obj_section_addr (section))
1358 return -1;
1359 if (pc < obj_section_endaddr (section))
1360 return 0;
1361 return 1;
1362 }
1363
1364 /* Returns a section whose range includes PC or NULL if none found. */
1365
1366 struct obj_section *
1367 find_pc_section (CORE_ADDR pc)
1368 {
1369 struct objfile_pspace_info *pspace_info;
1370 struct obj_section *s, **sp;
1371
1372 /* Check for mapped overlay section first. */
1373 s = find_pc_mapped_section (pc);
1374 if (s)
1375 return s;
1376
1377 pspace_info = get_objfile_pspace_data (current_program_space);
1378 if (pspace_info->section_map_dirty
1379 || (pspace_info->new_objfiles_available
1380 && !pspace_info->inhibit_updates))
1381 {
1382 update_section_map (current_program_space,
1383 &pspace_info->sections,
1384 &pspace_info->num_sections);
1385
1386 /* Don't need updates to section map until objfiles are added,
1387 removed or relocated. */
1388 pspace_info->new_objfiles_available = 0;
1389 pspace_info->section_map_dirty = 0;
1390 }
1391
1392 /* The C standard (ISO/IEC 9899:TC2) requires the BASE argument to
1393 bsearch be non-NULL. */
1394 if (pspace_info->sections == NULL)
1395 {
1396 gdb_assert (pspace_info->num_sections == 0);
1397 return NULL;
1398 }
1399
1400 sp = (struct obj_section **) bsearch (&pc,
1401 pspace_info->sections,
1402 pspace_info->num_sections,
1403 sizeof (*pspace_info->sections),
1404 bsearch_cmp);
1405 if (sp != NULL)
1406 return *sp;
1407 return NULL;
1408 }
1409
1410
1411 /* Return non-zero if PC is in a section called NAME. */
1412
1413 int
1414 pc_in_section (CORE_ADDR pc, const char *name)
1415 {
1416 struct obj_section *s;
1417 int retval = 0;
1418
1419 s = find_pc_section (pc);
1420
1421 retval = (s != NULL
1422 && s->the_bfd_section->name != NULL
1423 && strcmp (s->the_bfd_section->name, name) == 0);
1424 return (retval);
1425 }
1426 \f
1427
1428 /* Set section_map_dirty so section map will be rebuilt next time it
1429 is used. Called by reread_symbols. */
1430
1431 void
1432 objfiles_changed (void)
1433 {
1434 /* Rebuild section map next time we need it. */
1435 get_objfile_pspace_data (current_program_space)->section_map_dirty = 1;
1436 }
1437
1438 /* See comments in objfiles.h. */
1439
1440 scoped_restore_tmpl<int>
1441 inhibit_section_map_updates (struct program_space *pspace)
1442 {
1443 return scoped_restore_tmpl<int>
1444 (&get_objfile_pspace_data (pspace)->inhibit_updates, 1);
1445 }
1446
1447 /* Return 1 if ADDR maps into one of the sections of OBJFILE and 0
1448 otherwise. */
1449
1450 int
1451 is_addr_in_objfile (CORE_ADDR addr, const struct objfile *objfile)
1452 {
1453 struct obj_section *osect;
1454
1455 if (objfile == NULL)
1456 return 0;
1457
1458 ALL_OBJFILE_OSECTIONS (objfile, osect)
1459 {
1460 if (section_is_overlay (osect) && !section_is_mapped (osect))
1461 continue;
1462
1463 if (obj_section_addr (osect) <= addr
1464 && addr < obj_section_endaddr (osect))
1465 return 1;
1466 }
1467 return 0;
1468 }
1469
1470 int
1471 shared_objfile_contains_address_p (struct program_space *pspace,
1472 CORE_ADDR address)
1473 {
1474 for (objfile *objfile : pspace->objfiles ())
1475 {
1476 if ((objfile->flags & OBJF_SHARED) != 0
1477 && is_addr_in_objfile (address, objfile))
1478 return 1;
1479 }
1480
1481 return 0;
1482 }
1483
1484 /* The default implementation for the "iterate_over_objfiles_in_search_order"
1485 gdbarch method. It is equivalent to use the objfiles iterable,
1486 searching the objfiles in the order they are stored internally,
1487 ignoring CURRENT_OBJFILE.
1488
1489 On most platorms, it should be close enough to doing the best
1490 we can without some knowledge specific to the architecture. */
1491
1492 void
1493 default_iterate_over_objfiles_in_search_order
1494 (struct gdbarch *gdbarch,
1495 iterate_over_objfiles_in_search_order_cb_ftype *cb,
1496 void *cb_data, struct objfile *current_objfile)
1497 {
1498 int stop = 0;
1499
1500 for (objfile *objfile : current_program_space->objfiles ())
1501 {
1502 stop = cb (objfile, cb_data);
1503 if (stop)
1504 return;
1505 }
1506 }
1507
1508 /* See objfiles.h. */
1509
1510 const char *
1511 objfile_name (const struct objfile *objfile)
1512 {
1513 if (objfile->obfd != NULL)
1514 return bfd_get_filename (objfile->obfd);
1515
1516 return objfile->original_name;
1517 }
1518
1519 /* See objfiles.h. */
1520
1521 const char *
1522 objfile_filename (const struct objfile *objfile)
1523 {
1524 if (objfile->obfd != NULL)
1525 return bfd_get_filename (objfile->obfd);
1526
1527 return NULL;
1528 }
1529
1530 /* See objfiles.h. */
1531
1532 const char *
1533 objfile_debug_name (const struct objfile *objfile)
1534 {
1535 return lbasename (objfile->original_name);
1536 }
1537
1538 /* See objfiles.h. */
1539
1540 const char *
1541 objfile_flavour_name (struct objfile *objfile)
1542 {
1543 if (objfile->obfd != NULL)
1544 return bfd_flavour_name (bfd_get_flavour (objfile->obfd));
1545 return NULL;
1546 }
1547
1548 void
1549 _initialize_objfiles (void)
1550 {
1551 objfiles_pspace_data
1552 = register_program_space_data_with_cleanup (NULL,
1553 objfiles_pspace_data_cleanup);
1554
1555 objfiles_bfd_data = register_bfd_data_with_cleanup (NULL,
1556 objfile_bfd_data_free);
1557 }
This page took 0.061661 seconds and 5 git commands to generate.