/* GDB routines for manipulating objfiles.
- Copyright 1992 Free Software Foundation, Inc.
+ Copyright 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* This file contains support routines for creating, manipulating, and
destroying objfile structures. */
#include "target.h"
#include <sys/types.h>
-#include <sys/stat.h>
+#include "gdb_stat.h"
#include <fcntl.h>
-#include <obstack.h>
+#include "obstack.h"
+#include "gdb_string.h"
/* Prototypes for local functions */
#endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
-/* Message to be printed before the error message, when an error occurs. */
-
-extern char *error_pre_print;
-
/* Externally visible variables that are owned by this module.
See declarations in objfile.h for more info. */
struct objfile *object_files; /* Linked list of all objfiles */
struct objfile *current_objfile; /* For symbol file being read in */
struct objfile *symfile_objfile; /* Main symbol table loaded from */
+struct objfile *rt_common_objfile; /* For runtime common symbols */
int mapped_symbol_files; /* Try to use mapped symbol files */
return;
section.offset = 0;
section.objfile = objfile;
- section.sec_ptr = asect;
+ section.the_bfd_section = asect;
section.addr = bfd_section_vma (abfd, asect);
section.endaddr = section.addr + bfd_section_size (abfd, asect);
obstack_grow (&objfile->psymbol_obstack, §ion, sizeof(section));
int mapped;
{
struct objfile *objfile = NULL;
+ struct objfile *last_one = NULL;
mapped |= mapped_symbol_files;
if (mapped)
{
- warning ("this version of gdb does not support mapped symbol tables.");
+ warning ("mapped symbol tables are not supported on this machine; missing or broken mmap().");
/* Turn off the global flag so we don't try to do mapped symbol tables
any more, which shuts up gdb unless the user specifically gives the
if (build_objfile_section_table (objfile))
{
error ("Can't find the file sections in `%s': %s",
- objfile -> name, bfd_errmsg (bfd_error));
+ objfile -> name, bfd_errmsg (bfd_get_error ()));
}
- /* Push this file onto the head of the linked list of other such files. */
-
- objfile -> next = object_files;
- object_files = objfile;
+ /* Add this file onto the tail of the linked list of other such files. */
+ objfile -> next = NULL;
+ if (object_files == NULL)
+ object_files = objfile;
+ else
+ {
+ for (last_one = object_files;
+ last_one -> next;
+ last_one = last_one -> next);
+ last_one -> next = objfile;
+ }
return (objfile);
}
+/* Put OBJFILE at the front of the list. */
+
+void
+objfile_to_front (objfile)
+ struct objfile *objfile;
+{
+ struct objfile **objp;
+ for (objp = &object_files; *objp != NULL; objp = &((*objp)->next))
+ {
+ if (*objp == objfile)
+ {
+ /* Unhook it from where it is. */
+ *objp = objfile->next;
+ /* Put it in the front. */
+ objfile->next = object_files;
+ object_files = objfile;
+ break;
+ }
+ }
+}
+
/* Unlink OBJFILE from the list of known objfiles, if it is found in the
list.
if (objfile -> obfd != NULL)
{
char *name = bfd_get_filename (objfile->obfd);
- bfd_close (objfile -> obfd);
+ if (!bfd_close (objfile -> obfd))
+ warning ("cannot close \"%s\": %s",
+ name, bfd_errmsg (bfd_get_error ()));
free (name);
}
unlink_objfile (objfile);
+ /* If we are going to free the runtime common objfile, mark it
+ as unallocated. */
+
+ if (objfile == rt_common_objfile)
+ rt_common_objfile = NULL;
+
/* Before the symbol table code was redone to make it easier to
selectively load and remove information particular to a specific
linkage unit, gdb used to do these things whenever the monolithic
{
struct symtab *s;
- for (s = objfile->symtabs; s; s = s->next)
+ ALL_OBJFILE_SYMTABS (objfile, s)
{
struct linetable *l;
struct blockvector *bv;
SYMBOL_VALUE_ADDRESS (sym) +=
ANOFFSET (delta, SYMBOL_SECTION (sym));
}
+#ifdef MIPS_EFI_SYMBOL_NAME
+ /* Relocate Extra Function Info for ecoff. */
+
+ else
+ if (SYMBOL_CLASS (sym) == LOC_CONST
+ && SYMBOL_NAMESPACE (sym) == LABEL_NAMESPACE
+ && STRCMP (SYMBOL_NAME (sym), MIPS_EFI_SYMBOL_NAME) == 0)
+ ecoff_relocate_efi (sym, ANOFFSET (delta, s->block_line_section));
+#endif
}
}
}
ALL_OBJFILE_PSYMTABS (objfile, p)
{
- /* FIXME: specific to symbol readers which use gdb-stabs.h.
- We can only get away with it since objfile_relocate is only
- used on XCOFF, which lacks psymtabs, and for gdb-stabs.h
- targets. */
p->textlow += ANOFFSET (delta, SECT_OFF_TEXT);
p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT);
}
if (SYMBOL_SECTION (msym) >= 0)
SYMBOL_VALUE_ADDRESS (msym) += ANOFFSET (delta, SYMBOL_SECTION (msym));
}
+ /* Relocating different sections by different amounts may cause the symbols
+ to be out of order. */
+ msymbols_sort (objfile);
{
int i;
for (i = 0; i < objfile->num_sections; ++i)
ANOFFSET (objfile->section_offsets, i) = ANOFFSET (new_offsets, i);
}
+
+ {
+ struct obj_section *s;
+ bfd *abfd;
+
+ abfd = objfile->obfd;
+
+ for (s = objfile->sections;
+ s < objfile->sections_end; ++s)
+ {
+ flagword flags;
+
+ flags = bfd_get_section_flags (abfd, s->the_bfd_section);
+
+ if (flags & SEC_CODE)
+ {
+ s->addr += ANOFFSET (delta, SECT_OFF_TEXT);
+ s->endaddr += ANOFFSET (delta, SECT_OFF_TEXT);
+ }
+ else if (flags & (SEC_DATA | SEC_LOAD))
+ {
+ s->addr += ANOFFSET (delta, SECT_OFF_DATA);
+ s->endaddr += ANOFFSET (delta, SECT_OFF_DATA);
+ }
+ else if (flags & SEC_ALLOC)
+ {
+ s->addr += ANOFFSET (delta, SECT_OFF_BSS);
+ s->endaddr += ANOFFSET (delta, SECT_OFF_BSS);
+ }
+ }
+ }
+
+ if (objfile->ei.entry_point != ~0)
+ objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT);
+
+ if (objfile->ei.entry_func_lowpc != INVALID_ENTRY_LOWPC)
+ {
+ objfile->ei.entry_func_lowpc += ANOFFSET (delta, SECT_OFF_TEXT);
+ objfile->ei.entry_func_highpc += ANOFFSET (delta, SECT_OFF_TEXT);
+ }
+
+ if (objfile->ei.entry_file_lowpc != INVALID_ENTRY_LOWPC)
+ {
+ objfile->ei.entry_file_lowpc += ANOFFSET (delta, SECT_OFF_TEXT);
+ objfile->ei.entry_file_highpc += ANOFFSET (delta, SECT_OFF_TEXT);
+ }
+
+ if (objfile->ei.main_func_lowpc != INVALID_ENTRY_LOWPC)
+ {
+ objfile->ei.main_func_lowpc += ANOFFSET (delta, SECT_OFF_TEXT);
+ objfile->ei.main_func_highpc += ANOFFSET (delta, SECT_OFF_TEXT);
+ }
}
\f
/* Many places in gdb want to test just to see if we have any partial
#else
+ warning ("need to recompile gdb with MMAP_BASE_ADDRESS and MMAP_INCREMENT defined");
return (0);
#endif
return(NULL);
}
+
+/* In SVR4, we recognize a trampoline by it's section name.
+ That is, if the pc is in a section named ".plt" then we are in
+ a trampoline. */
+
+int
+in_plt_section(pc, name)
+ CORE_ADDR pc;
+ char *name;
+{
+ struct obj_section *s;
+ int retval = 0;
+
+ s = find_pc_section(pc);
+
+ retval = (s != NULL
+ && s->the_bfd_section->name != NULL
+ && STREQ (s->the_bfd_section->name, ".plt"));
+ return(retval);
+}