/* GDB routines for manipulating objfiles.
- Copyright 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+ Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
This file is part of GDB.
#if defined(USE_MMALLOC) && defined(HAVE_MMAP)
+#include "mmalloc.h"
+
static int open_existing_mapped_file (char *, long, int);
static int open_mapped_file (char *filename, long mtime, int flags);
objfile->mmfd = fd;
/* Update pointers to functions to *our* copies */
obstack_chunkfun (&objfile->psymbol_cache.cache, xmmalloc);
- obstack_freefun (&objfile->psymbol_cache.cache, mfree);
+ obstack_freefun (&objfile->psymbol_cache.cache, xmfree);
+ obstack_chunkfun (&objfile->macro_cache.cache, xmmalloc);
+ obstack_freefun (&objfile->macro_cache.cache, xmfree);
obstack_chunkfun (&objfile->psymbol_obstack, xmmalloc);
- obstack_freefun (&objfile->psymbol_obstack, mfree);
+ obstack_freefun (&objfile->psymbol_obstack, xmfree);
obstack_chunkfun (&objfile->symbol_obstack, xmmalloc);
- obstack_freefun (&objfile->symbol_obstack, mfree);
+ obstack_freefun (&objfile->symbol_obstack, xmfree);
obstack_chunkfun (&objfile->type_obstack, xmmalloc);
- obstack_freefun (&objfile->type_obstack, mfree);
+ obstack_freefun (&objfile->type_obstack, xmfree);
/* If already in objfile list, unlink it. */
unlink_objfile (objfile);
/* Forget things specific to a particular gdb, may have changed. */
objfile->flags |= OBJF_MAPPED;
mmalloc_setkey (objfile->md, 0, objfile);
obstack_specify_allocation_with_arg (&objfile->psymbol_cache.cache,
- 0, 0, xmmalloc, mfree,
+ 0, 0, xmmalloc, xmfree,
+ objfile->md);
+ obstack_specify_allocation_with_arg (&objfile->macro_cache.cache,
+ 0, 0, xmmalloc, xmfree,
objfile->md);
obstack_specify_allocation_with_arg (&objfile->psymbol_obstack,
- 0, 0, xmmalloc, mfree,
+ 0, 0, xmmalloc, xmfree,
objfile->md);
obstack_specify_allocation_with_arg (&objfile->symbol_obstack,
- 0, 0, xmmalloc, mfree,
+ 0, 0, xmmalloc, xmfree,
objfile->md);
obstack_specify_allocation_with_arg (&objfile->type_obstack,
- 0, 0, xmmalloc, mfree,
+ 0, 0, xmmalloc, xmfree,
objfile->md);
}
}
memset (objfile, 0, sizeof (struct objfile));
objfile->md = NULL;
obstack_specify_allocation (&objfile->psymbol_cache.cache, 0, 0,
- xmalloc, free);
+ xmalloc, xfree);
+ obstack_specify_allocation (&objfile->macro_cache.cache, 0, 0,
+ xmalloc, xfree);
obstack_specify_allocation (&objfile->psymbol_obstack, 0, 0, xmalloc,
- free);
+ xfree);
obstack_specify_allocation (&objfile->symbol_obstack, 0, 0, xmalloc,
- free);
+ xfree);
obstack_specify_allocation (&objfile->type_obstack, 0, 0, xmalloc,
- free);
+ xfree);
flags &= ~OBJF_MAPPED;
}
objfile->obfd = abfd;
if (objfile->name != NULL)
{
- mfree (objfile->md, objfile->name);
+ xmfree (objfile->md, objfile->name);
}
if (abfd != NULL)
{
}
}
- internal_error ("objfiles.c (unlink_objfile): objfile already unlinked");
+ internal_error (__FILE__, __LINE__,
+ "unlink_objfile: objfile already unlinked");
}
if (!bfd_close (objfile->obfd))
warning ("cannot close \"%s\": %s",
name, bfd_errmsg (bfd_get_error ()));
- free (name);
+ xfree (name);
}
/* Remove it from the chain of all objfiles. */
clear_pc_function_cache ();
/* The last thing we do is free the objfile struct itself for the
- non-reusable case, or detach from the mapped file for the reusable
- case. Note that the mmalloc_detach or the mfree is the last thing
- we can do with this objfile. */
+ non-reusable case, or detach from the mapped file for the
+ reusable case. Note that the mmalloc_detach or the xmfree() is
+ the last thing we can do with this objfile. */
#if defined(USE_MMALLOC) && defined(HAVE_MMAP)
{
if (objfile->name != NULL)
{
- mfree (objfile->md, objfile->name);
+ xmfree (objfile->md, objfile->name);
}
if (objfile->global_psymbols.list)
- mfree (objfile->md, objfile->global_psymbols.list);
+ xmfree (objfile->md, objfile->global_psymbols.list);
if (objfile->static_psymbols.list)
- mfree (objfile->md, objfile->static_psymbols.list);
+ xmfree (objfile->md, objfile->static_psymbols.list);
/* Free the obstacks for non-reusable objfiles */
free_bcache (&objfile->psymbol_cache);
+ free_bcache (&objfile->macro_cache);
obstack_free (&objfile->psymbol_obstack, 0);
obstack_free (&objfile->symbol_obstack, 0);
obstack_free (&objfile->type_obstack, 0);
- mfree (objfile->md, objfile);
+ xmfree (objfile->md, objfile);
objfile = NULL;
}
}
for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i)
{
struct block *b;
+ struct symbol *sym;
int j;
b = BLOCKVECTOR_BLOCK (bv, i);
BLOCK_START (b) += ANOFFSET (delta, s->block_line_section);
BLOCK_END (b) += ANOFFSET (delta, s->block_line_section);
- for (j = 0; j < BLOCK_NSYMS (b); ++j)
+ ALL_BLOCK_SYMBOLS (b, j, sym)
{
- struct symbol *sym = BLOCK_SYM (b, j);
-
fixup_symbol_section (sym, objfile);
/* The RS6000 code from which this was taken skipped
else if (SYMBOL_CLASS (sym) == LOC_CONST
&& SYMBOL_NAMESPACE (sym) == LABEL_NAMESPACE
- && STRCMP (SYMBOL_NAME (sym), MIPS_EFI_SYMBOL_NAME) == 0)
+ && strcmp (SYMBOL_NAME (sym), MIPS_EFI_SYMBOL_NAME) == 0)
ecoff_relocate_efi (sym, ANOFFSET (delta,
s->block_line_section));
#endif
(objfile->section_offsets)->offsets[i] = ANOFFSET (new_offsets, i);
}
+ if (objfile->ei.entry_point != ~(CORE_ADDR) 0)
+ {
+ /* Relocate ei.entry_point with its section offset, use SECT_OFF_TEXT
+ only as a fallback. */
+ struct obj_section *s;
+ s = find_pc_section (objfile->ei.entry_point);
+ if (s)
+ objfile->ei.entry_point += ANOFFSET (delta, s->the_bfd_section->index);
+ else
+ objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
+ }
+
{
struct obj_section *s;
bfd *abfd;
ALL_OBJFILE_OSECTIONS (objfile, s)
{
- flagword flags;
-
- flags = bfd_get_section_flags (abfd, s->the_bfd_section);
-
- if (flags & SEC_CODE)
- {
- s->addr += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
- s->endaddr += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
- }
- else if (flags & (SEC_DATA | SEC_LOAD))
- {
- s->addr += ANOFFSET (delta, SECT_OFF_DATA (objfile));
- s->endaddr += ANOFFSET (delta, SECT_OFF_DATA (objfile));
- }
- else if (flags & SEC_ALLOC)
- {
- s->addr += ANOFFSET (delta, SECT_OFF_BSS (objfile));
- s->endaddr += ANOFFSET (delta, SECT_OFF_BSS (objfile));
- }
+ int idx = s->the_bfd_section->index;
+
+ s->addr += ANOFFSET (delta, idx);
+ s->endaddr += ANOFFSET (delta, idx);
}
}
- if (objfile->ei.entry_point != ~(CORE_ADDR) 0)
- objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-
if (objfile->ei.entry_func_lowpc != INVALID_ENTRY_LOWPC)
{
objfile->ei.entry_func_lowpc += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
/* First try to open an existing file in the current directory, and
then try the directory where the symbol file is located. */
- symsfilename = concat ("./", basename (filename), ".syms", (char *) NULL);
+ symsfilename = concat ("./", lbasename (filename), ".syms", (char *) NULL);
if ((fd = open_existing_mapped_file (symsfilename, mtime, flags)) < 0)
{
- free (symsfilename);
+ xfree (symsfilename);
symsfilename = concat (filename, ".syms", (char *) NULL);
fd = open_existing_mapped_file (symsfilename, mtime, flags);
}
if ((fd < 0) && (flags & OBJF_MAPPED))
{
- free (symsfilename);
- symsfilename = concat ("./", basename (filename), ".syms",
+ xfree (symsfilename);
+ symsfilename = concat ("./", lbasename (filename), ".syms",
(char *) NULL);
if ((fd = open (symsfilename, O_RDWR | O_CREAT | O_TRUNC, 0666)) < 0)
{
}
}
- free (symsfilename);
+ xfree (symsfilename);
return (fd);
}