Fix some WARNS6 regression that crept up in the last days.
[dragonfly.git] / contrib / gdb-6 / gdb / objfiles.c
blob5b7b12fa224ea514e107185d52668b7e84287ec2
1 /* GDB routines for manipulating objfiles.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
6 Contributed by Cygnus Support, using pieces from other GDB modules.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* This file contains support routines for creating, manipulating, and
24 destroying objfile structures. */
26 #include "defs.h"
27 #include "bfd.h" /* Binary File Description */
28 #include "symtab.h"
29 #include "symfile.h"
30 #include "objfiles.h"
31 #include "gdb-stabs.h"
32 #include "target.h"
33 #include "bcache.h"
34 #include "mdebugread.h"
35 #include "expression.h"
36 #include "parser-defs.h"
38 #include "gdb_assert.h"
39 #include <sys/types.h>
40 #include "gdb_stat.h"
41 #include <fcntl.h>
42 #include "gdb_obstack.h"
43 #include "gdb_string.h"
44 #include "hashtab.h"
46 #include "breakpoint.h"
47 #include "block.h"
48 #include "dictionary.h"
49 #include "source.h"
51 /* Prototypes for local functions */
53 static void objfile_alloc_data (struct objfile *objfile);
54 static void objfile_free_data (struct objfile *objfile);
56 /* Externally visible variables that are owned by this module.
57 See declarations in objfile.h for more info. */
59 struct objfile *object_files; /* Linked list of all objfiles */
60 struct objfile *current_objfile; /* For symbol file being read in */
61 struct objfile *symfile_objfile; /* Main symbol table loaded from */
62 struct objfile *rt_common_objfile; /* For runtime common symbols */
64 /* Locate all mappable sections of a BFD file.
65 objfile_p_char is a char * to get it through
66 bfd_map_over_sections; we cast it back to its proper type. */
68 #ifndef TARGET_KEEP_SECTION
69 #define TARGET_KEEP_SECTION(ASECT) 0
70 #endif
72 /* Called via bfd_map_over_sections to build up the section table that
73 the objfile references. The objfile contains pointers to the start
74 of the table (objfile->sections) and to the first location after
75 the end of the table (objfile->sections_end). */
77 static void
78 add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
79 void *objfile_p_char)
81 struct objfile *objfile = (struct objfile *) objfile_p_char;
82 struct obj_section section;
83 flagword aflag;
85 aflag = bfd_get_section_flags (abfd, asect);
87 if (!(aflag & SEC_ALLOC) && !(TARGET_KEEP_SECTION (asect)))
88 return;
90 if (0 == bfd_section_size (abfd, asect))
91 return;
92 section.offset = 0;
93 section.objfile = objfile;
94 section.the_bfd_section = asect;
95 section.ovly_mapped = 0;
96 section.addr = bfd_section_vma (abfd, asect);
97 section.endaddr = section.addr + bfd_section_size (abfd, asect);
98 obstack_grow (&objfile->objfile_obstack, (char *) &section, sizeof (section));
99 objfile->sections_end = (struct obj_section *) (((unsigned long) objfile->sections_end) + 1);
102 /* Builds a section table for OBJFILE.
103 Returns 0 if OK, 1 on error (in which case bfd_error contains the
104 error).
106 Note that while we are building the table, which goes into the
107 psymbol obstack, we hijack the sections_end pointer to instead hold
108 a count of the number of sections. When bfd_map_over_sections
109 returns, this count is used to compute the pointer to the end of
110 the sections table, which then overwrites the count.
112 Also note that the OFFSET and OVLY_MAPPED in each table entry
113 are initialized to zero.
115 Also note that if anything else writes to the psymbol obstack while
116 we are building the table, we're pretty much hosed. */
119 build_objfile_section_table (struct objfile *objfile)
121 /* objfile->sections can be already set when reading a mapped symbol
122 file. I believe that we do need to rebuild the section table in
123 this case (we rebuild other things derived from the bfd), but we
124 can't free the old one (it's in the objfile_obstack). So we just
125 waste some memory. */
127 objfile->sections_end = 0;
128 bfd_map_over_sections (objfile->obfd, add_to_objfile_sections, (char *) objfile);
129 objfile->sections = (struct obj_section *)
130 obstack_finish (&objfile->objfile_obstack);
131 objfile->sections_end = objfile->sections + (unsigned long) objfile->sections_end;
132 return (0);
135 /* Given a pointer to an initialized bfd (ABFD) and some flag bits
136 allocate a new objfile struct, fill it in as best we can, link it
137 into the list of all known objfiles, and return a pointer to the
138 new objfile struct.
140 The FLAGS word contains various bits (OBJF_*) that can be taken as
141 requests for specific operations. Other bits like OBJF_SHARED are
142 simply copied through to the new objfile flags member. */
144 /* NOTE: carlton/2003-02-04: This function is called with args NULL, 0
145 by jv-lang.c, to create an artificial objfile used to hold
146 information about dynamically-loaded Java classes. Unfortunately,
147 that branch of this function doesn't get tested very frequently, so
148 it's prone to breakage. (E.g. at one time the name was set to NULL
149 in that situation, which broke a loop over all names in the dynamic
150 library loader.) If you change this function, please try to leave
151 things in a consistent state even if abfd is NULL. */
153 struct objfile *
154 allocate_objfile (bfd *abfd, int flags)
156 struct objfile *objfile = NULL;
157 struct objfile *last_one = NULL;
159 /* If we don't support mapped symbol files, didn't ask for the file to be
160 mapped, or failed to open the mapped file for some reason, then revert
161 back to an unmapped objfile. */
163 if (objfile == NULL)
165 objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
166 memset (objfile, 0, sizeof (struct objfile));
167 objfile->md = NULL;
168 objfile->psymbol_cache = bcache_xmalloc ();
169 objfile->macro_cache = bcache_xmalloc ();
170 /* We could use obstack_specify_allocation here instead, but
171 gdb_obstack.h specifies the alloc/dealloc functions. */
172 obstack_init (&objfile->objfile_obstack);
173 terminate_minimal_symbol_table (objfile);
176 objfile_alloc_data (objfile);
178 /* Update the per-objfile information that comes from the bfd, ensuring
179 that any data that is reference is saved in the per-objfile data
180 region. */
182 objfile->obfd = abfd;
183 if (objfile->name != NULL)
185 xfree (objfile->name);
187 if (abfd != NULL)
189 objfile->name = xstrdup (bfd_get_filename (abfd));
190 objfile->mtime = bfd_get_mtime (abfd);
192 /* Build section table. */
194 if (build_objfile_section_table (objfile))
196 error (_("Can't find the file sections in `%s': %s"),
197 objfile->name, bfd_errmsg (bfd_get_error ()));
200 else
202 objfile->name = xstrdup ("<<anonymous objfile>>");
205 /* Initialize the section indexes for this objfile, so that we can
206 later detect if they are used w/o being properly assigned to. */
208 objfile->sect_index_text = -1;
209 objfile->sect_index_data = -1;
210 objfile->sect_index_bss = -1;
211 objfile->sect_index_rodata = -1;
213 /* We don't yet have a C++-specific namespace symtab. */
215 objfile->cp_namespace_symtab = NULL;
217 /* Add this file onto the tail of the linked list of other such files. */
219 objfile->next = NULL;
220 if (object_files == NULL)
221 object_files = objfile;
222 else
224 for (last_one = object_files;
225 last_one->next;
226 last_one = last_one->next);
227 last_one->next = objfile;
230 /* Save passed in flag bits. */
231 objfile->flags |= flags;
233 return (objfile);
236 /* Initialize entry point information for this objfile. */
238 void
239 init_entry_point_info (struct objfile *objfile)
241 /* Save startup file's range of PC addresses to help blockframe.c
242 decide where the bottom of the stack is. */
244 if (bfd_get_file_flags (objfile->obfd) & EXEC_P)
246 /* Executable file -- record its entry point so we'll recognize
247 the startup file because it contains the entry point. */
248 objfile->ei.entry_point = bfd_get_start_address (objfile->obfd);
250 else
252 /* Examination of non-executable.o files. Short-circuit this stuff. */
253 objfile->ei.entry_point = INVALID_ENTRY_POINT;
257 /* Get current entry point address. */
259 CORE_ADDR
260 entry_point_address (void)
262 return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
265 /* Create the terminating entry of OBJFILE's minimal symbol table.
266 If OBJFILE->msymbols is zero, allocate a single entry from
267 OBJFILE->objfile_obstack; otherwise, just initialize
268 OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */
269 void
270 terminate_minimal_symbol_table (struct objfile *objfile)
272 if (! objfile->msymbols)
273 objfile->msymbols = ((struct minimal_symbol *)
274 obstack_alloc (&objfile->objfile_obstack,
275 sizeof (objfile->msymbols[0])));
278 struct minimal_symbol *m
279 = &objfile->msymbols[objfile->minimal_symbol_count];
281 memset (m, 0, sizeof (*m));
282 /* Don't rely on these enumeration values being 0's. */
283 MSYMBOL_TYPE (m) = mst_unknown;
284 SYMBOL_INIT_LANGUAGE_SPECIFIC (m, language_unknown);
289 /* Put one object file before a specified on in the global list.
290 This can be used to make sure an object file is destroyed before
291 another when using ALL_OBJFILES_SAFE to free all objfiles. */
292 void
293 put_objfile_before (struct objfile *objfile, struct objfile *before_this)
295 struct objfile **objp;
297 unlink_objfile (objfile);
299 for (objp = &object_files; *objp != NULL; objp = &((*objp)->next))
301 if (*objp == before_this)
303 objfile->next = *objp;
304 *objp = objfile;
305 return;
309 internal_error (__FILE__, __LINE__,
310 _("put_objfile_before: before objfile not in list"));
313 /* Put OBJFILE at the front of the list. */
315 void
316 objfile_to_front (struct objfile *objfile)
318 struct objfile **objp;
319 for (objp = &object_files; *objp != NULL; objp = &((*objp)->next))
321 if (*objp == objfile)
323 /* Unhook it from where it is. */
324 *objp = objfile->next;
325 /* Put it in the front. */
326 objfile->next = object_files;
327 object_files = objfile;
328 break;
333 /* Unlink OBJFILE from the list of known objfiles, if it is found in the
334 list.
336 It is not a bug, or error, to call this function if OBJFILE is not known
337 to be in the current list. This is done in the case of mapped objfiles,
338 for example, just to ensure that the mapped objfile doesn't appear twice
339 in the list. Since the list is threaded, linking in a mapped objfile
340 twice would create a circular list.
342 If OBJFILE turns out to be in the list, we zap it's NEXT pointer after
343 unlinking it, just to ensure that we have completely severed any linkages
344 between the OBJFILE and the list. */
346 void
347 unlink_objfile (struct objfile *objfile)
349 struct objfile **objpp;
351 for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp)->next))
353 if (*objpp == objfile)
355 *objpp = (*objpp)->next;
356 objfile->next = NULL;
357 return;
361 internal_error (__FILE__, __LINE__,
362 _("unlink_objfile: objfile already unlinked"));
366 /* Destroy an objfile and all the symtabs and psymtabs under it. Note
367 that as much as possible is allocated on the objfile_obstack
368 so that the memory can be efficiently freed.
370 Things which we do NOT free because they are not in malloc'd memory
371 or not in memory specific to the objfile include:
373 objfile -> sf
375 FIXME: If the objfile is using reusable symbol information (via mmalloc),
376 then we need to take into account the fact that more than one process
377 may be using the symbol information at the same time (when mmalloc is
378 extended to support cooperative locking). When more than one process
379 is using the mapped symbol info, we need to be more careful about when
380 we free objects in the reusable area. */
382 void
383 free_objfile (struct objfile *objfile)
385 if (objfile->separate_debug_objfile)
387 free_objfile (objfile->separate_debug_objfile);
390 if (objfile->separate_debug_objfile_backlink)
392 /* We freed the separate debug file, make sure the base objfile
393 doesn't reference it. */
394 objfile->separate_debug_objfile_backlink->separate_debug_objfile = NULL;
397 /* Remove any references to this objfile in the global value
398 lists. */
399 preserve_values (objfile);
401 /* First do any symbol file specific actions required when we are
402 finished with a particular symbol file. Note that if the objfile
403 is using reusable symbol information (via mmalloc) then each of
404 these routines is responsible for doing the correct thing, either
405 freeing things which are valid only during this particular gdb
406 execution, or leaving them to be reused during the next one. */
408 if (objfile->sf != NULL)
410 (*objfile->sf->sym_finish) (objfile);
413 /* We always close the bfd. */
415 if (objfile->obfd != NULL)
417 char *name = bfd_get_filename (objfile->obfd);
418 if (!bfd_close (objfile->obfd))
419 warning (_("cannot close \"%s\": %s"),
420 name, bfd_errmsg (bfd_get_error ()));
421 xfree (name);
424 /* Remove it from the chain of all objfiles. */
426 unlink_objfile (objfile);
428 /* If we are going to free the runtime common objfile, mark it
429 as unallocated. */
431 if (objfile == rt_common_objfile)
432 rt_common_objfile = NULL;
434 /* Before the symbol table code was redone to make it easier to
435 selectively load and remove information particular to a specific
436 linkage unit, gdb used to do these things whenever the monolithic
437 symbol table was blown away. How much still needs to be done
438 is unknown, but we play it safe for now and keep each action until
439 it is shown to be no longer needed. */
441 /* Not all our callers call clear_symtab_users (objfile_purge_solibs,
442 for example), so we need to call this here. */
443 clear_pc_function_cache ();
445 /* Clear globals which might have pointed into a removed objfile.
446 FIXME: It's not clear which of these are supposed to persist
447 between expressions and which ought to be reset each time. */
448 expression_context_block = NULL;
449 innermost_block = NULL;
451 /* Check to see if the current_source_symtab belongs to this objfile,
452 and if so, call clear_current_source_symtab_and_line. */
455 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
456 struct symtab *s;
458 ALL_OBJFILE_SYMTABS (objfile, s)
460 if (s == cursal.symtab)
461 clear_current_source_symtab_and_line ();
465 /* The last thing we do is free the objfile struct itself. */
467 objfile_free_data (objfile);
468 if (objfile->name != NULL)
470 xfree (objfile->name);
472 if (objfile->global_psymbols.list)
473 xfree (objfile->global_psymbols.list);
474 if (objfile->static_psymbols.list)
475 xfree (objfile->static_psymbols.list);
476 /* Free the obstacks for non-reusable objfiles */
477 bcache_xfree (objfile->psymbol_cache);
478 bcache_xfree (objfile->macro_cache);
479 if (objfile->demangled_names_hash)
480 htab_delete (objfile->demangled_names_hash);
481 obstack_free (&objfile->objfile_obstack, 0);
482 xfree (objfile);
483 objfile = NULL;
486 static void
487 do_free_objfile_cleanup (void *obj)
489 free_objfile (obj);
492 struct cleanup *
493 make_cleanup_free_objfile (struct objfile *obj)
495 return make_cleanup (do_free_objfile_cleanup, obj);
498 /* Free all the object files at once and clean up their users. */
500 void
501 free_all_objfiles (void)
503 struct objfile *objfile, *temp;
505 ALL_OBJFILES_SAFE (objfile, temp)
507 free_objfile (objfile);
509 clear_symtab_users ();
512 /* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS
513 entries in new_offsets. */
514 void
515 objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
517 struct section_offsets *delta =
518 ((struct section_offsets *)
519 alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)));
522 int i;
523 int something_changed = 0;
524 for (i = 0; i < objfile->num_sections; ++i)
526 delta->offsets[i] =
527 ANOFFSET (new_offsets, i) - ANOFFSET (objfile->section_offsets, i);
528 if (ANOFFSET (delta, i) != 0)
529 something_changed = 1;
531 if (!something_changed)
532 return;
535 /* OK, get all the symtabs. */
537 struct symtab *s;
539 ALL_OBJFILE_SYMTABS (objfile, s)
541 struct linetable *l;
542 struct blockvector *bv;
543 int i;
545 /* First the line table. */
546 l = LINETABLE (s);
547 if (l)
549 for (i = 0; i < l->nitems; ++i)
550 l->item[i].pc += ANOFFSET (delta, s->block_line_section);
553 /* Don't relocate a shared blockvector more than once. */
554 if (!s->primary)
555 continue;
557 bv = BLOCKVECTOR (s);
558 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i)
560 struct block *b;
561 struct symbol *sym;
562 struct dict_iterator iter;
564 b = BLOCKVECTOR_BLOCK (bv, i);
565 BLOCK_START (b) += ANOFFSET (delta, s->block_line_section);
566 BLOCK_END (b) += ANOFFSET (delta, s->block_line_section);
568 ALL_BLOCK_SYMBOLS (b, iter, sym)
570 fixup_symbol_section (sym, objfile);
572 /* The RS6000 code from which this was taken skipped
573 any symbols in STRUCT_DOMAIN or UNDEF_DOMAIN.
574 But I'm leaving out that test, on the theory that
575 they can't possibly pass the tests below. */
576 if ((SYMBOL_CLASS (sym) == LOC_LABEL
577 || SYMBOL_CLASS (sym) == LOC_STATIC
578 || SYMBOL_CLASS (sym) == LOC_INDIRECT)
579 && SYMBOL_SECTION (sym) >= 0)
581 SYMBOL_VALUE_ADDRESS (sym) +=
582 ANOFFSET (delta, SYMBOL_SECTION (sym));
590 struct partial_symtab *p;
592 ALL_OBJFILE_PSYMTABS (objfile, p)
594 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
595 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
600 struct partial_symbol **psym;
602 for (psym = objfile->global_psymbols.list;
603 psym < objfile->global_psymbols.next;
604 psym++)
606 fixup_psymbol_section (*psym, objfile);
607 if (SYMBOL_SECTION (*psym) >= 0)
608 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
609 SYMBOL_SECTION (*psym));
611 for (psym = objfile->static_psymbols.list;
612 psym < objfile->static_psymbols.next;
613 psym++)
615 fixup_psymbol_section (*psym, objfile);
616 if (SYMBOL_SECTION (*psym) >= 0)
617 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
618 SYMBOL_SECTION (*psym));
623 struct minimal_symbol *msym;
624 ALL_OBJFILE_MSYMBOLS (objfile, msym)
625 if (SYMBOL_SECTION (msym) >= 0)
626 SYMBOL_VALUE_ADDRESS (msym) += ANOFFSET (delta, SYMBOL_SECTION (msym));
628 /* Relocating different sections by different amounts may cause the symbols
629 to be out of order. */
630 msymbols_sort (objfile);
633 int i;
634 for (i = 0; i < objfile->num_sections; ++i)
635 (objfile->section_offsets)->offsets[i] = ANOFFSET (new_offsets, i);
638 if (objfile->ei.entry_point != ~(CORE_ADDR) 0)
640 /* Relocate ei.entry_point with its section offset, use SECT_OFF_TEXT
641 only as a fallback. */
642 struct obj_section *s;
643 s = find_pc_section (objfile->ei.entry_point);
644 if (s)
645 objfile->ei.entry_point += ANOFFSET (delta, s->the_bfd_section->index);
646 else
647 objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
651 struct obj_section *s;
652 bfd *abfd;
654 abfd = objfile->obfd;
656 ALL_OBJFILE_OSECTIONS (objfile, s)
658 int idx = s->the_bfd_section->index;
660 s->addr += ANOFFSET (delta, idx);
661 s->endaddr += ANOFFSET (delta, idx);
665 /* Relocate breakpoints as necessary, after things are relocated. */
666 breakpoint_re_set ();
669 /* Many places in gdb want to test just to see if we have any partial
670 symbols available. This function returns zero if none are currently
671 available, nonzero otherwise. */
674 have_partial_symbols (void)
676 struct objfile *ofp;
678 ALL_OBJFILES (ofp)
680 if (ofp->psymtabs != NULL)
682 return 1;
685 return 0;
688 /* Many places in gdb want to test just to see if we have any full
689 symbols available. This function returns zero if none are currently
690 available, nonzero otherwise. */
693 have_full_symbols (void)
695 struct objfile *ofp;
697 ALL_OBJFILES (ofp)
699 if (ofp->symtabs != NULL)
701 return 1;
704 return 0;
708 /* This operations deletes all objfile entries that represent solibs that
709 weren't explicitly loaded by the user, via e.g., the add-symbol-file
710 command.
712 void
713 objfile_purge_solibs (void)
715 struct objfile *objf;
716 struct objfile *temp;
718 ALL_OBJFILES_SAFE (objf, temp)
720 /* We assume that the solib package has been purged already, or will
721 be soon.
723 if (!(objf->flags & OBJF_USERLOADED) && (objf->flags & OBJF_SHARED))
724 free_objfile (objf);
729 /* Many places in gdb want to test just to see if we have any minimal
730 symbols available. This function returns zero if none are currently
731 available, nonzero otherwise. */
734 have_minimal_symbols (void)
736 struct objfile *ofp;
738 ALL_OBJFILES (ofp)
740 if (ofp->minimal_symbol_count > 0)
742 return 1;
745 return 0;
748 /* Returns a section whose range includes PC and SECTION, or NULL if
749 none found. Note the distinction between the return type, struct
750 obj_section (which is defined in gdb), and the input type "struct
751 bfd_section" (which is a bfd-defined data type). The obj_section
752 contains a pointer to the "struct bfd_section". */
754 struct obj_section *
755 find_pc_sect_section (CORE_ADDR pc, struct bfd_section *section)
757 struct obj_section *s;
758 struct objfile *objfile;
760 ALL_OBJSECTIONS (objfile, s)
761 if ((section == 0 || section == s->the_bfd_section) &&
762 s->addr <= pc && pc < s->endaddr)
763 return (s);
765 return (NULL);
768 /* Returns a section whose range includes PC or NULL if none found.
769 Backward compatibility, no section. */
771 struct obj_section *
772 find_pc_section (CORE_ADDR pc)
774 return find_pc_sect_section (pc, find_pc_mapped_section (pc));
778 /* In SVR4, we recognize a trampoline by it's section name.
779 That is, if the pc is in a section named ".plt" then we are in
780 a trampoline. */
783 in_plt_section (CORE_ADDR pc, char *name)
785 struct obj_section *s;
786 int retval = 0;
788 s = find_pc_section (pc);
790 retval = (s != NULL
791 && s->the_bfd_section->name != NULL
792 && strcmp (s->the_bfd_section->name, ".plt") == 0);
793 return (retval);
797 /* Keep a registry of per-objfile data-pointers required by other GDB
798 modules. */
800 struct objfile_data
802 unsigned index;
805 struct objfile_data_registration
807 struct objfile_data *data;
808 struct objfile_data_registration *next;
811 struct objfile_data_registry
813 struct objfile_data_registration *registrations;
814 unsigned num_registrations;
817 static struct objfile_data_registry objfile_data_registry = { NULL, 0 };
819 const struct objfile_data *
820 register_objfile_data (void)
822 struct objfile_data_registration **curr;
824 /* Append new registration. */
825 for (curr = &objfile_data_registry.registrations;
826 *curr != NULL; curr = &(*curr)->next);
828 *curr = XMALLOC (struct objfile_data_registration);
829 (*curr)->next = NULL;
830 (*curr)->data = XMALLOC (struct objfile_data);
831 (*curr)->data->index = objfile_data_registry.num_registrations++;
833 return (*curr)->data;
836 static void
837 objfile_alloc_data (struct objfile *objfile)
839 gdb_assert (objfile->data == NULL);
840 objfile->num_data = objfile_data_registry.num_registrations;
841 objfile->data = XCALLOC (objfile->num_data, void *);
844 static void
845 objfile_free_data (struct objfile *objfile)
847 gdb_assert (objfile->data != NULL);
848 xfree (objfile->data);
849 objfile->data = NULL;
852 void
853 clear_objfile_data (struct objfile *objfile)
855 gdb_assert (objfile->data != NULL);
856 memset (objfile->data, 0, objfile->num_data * sizeof (void *));
859 void
860 set_objfile_data (struct objfile *objfile, const struct objfile_data *data,
861 void *value)
863 gdb_assert (data->index < objfile->num_data);
864 objfile->data[data->index] = value;
867 void *
868 objfile_data (struct objfile *objfile, const struct objfile_data *data)
870 gdb_assert (data->index < objfile->num_data);
871 return objfile->data[data->index];