-
-/* vmap_symtab - handle symbol translation on vmapping */
-
-vmap_symtab(vp, old_start, vip)
-register struct vmap *vp;
-CORE_ADDR old_start;
-struct stat *vip;
-{
- register struct symtab *s;
- register struct objfile *objfile;
- register struct minimal_symbol *msymbol;
-
- /*
- * for each symbol table generated from the vp->bfd
- */
- ALL_OBJFILES (objfile)
- {
- for (s = objfile -> symtabs; s != NULL; s = s -> next) {
-
- /* skip over if this is not relocatable and doesn't have a line table */
- if (s->nonreloc && !LINETABLE (s))
- continue;
-
- /* matching the symbol table's BFD and the *vp's BFD is hairy.
- exec_file creates a seperate BFD for possibly the
- same file as symbol_file.FIXME ALL THIS MUST BE RECTIFIED. */
-
- if (objfile->obfd == vp->bfd) {
- /* if they match, we luck out. */
- ;
- } else if (vp->member[0]) {
- /* no match, and member present, not this one. */
- continue;
- } else {
- struct stat si;
- FILE *io;
-
- /*
- * no match, and no member. need to be sure.
- */
- io = bfd_cache_lookup(objfile->obfd);
- if (!io)
- fatal("cannot find BFD's iostream for sym");
- /*
- * see if we are referring to the same file
- */
- if (fstat(fileno(io), &si) < 0)
- fatal("cannot fstat BFD for sym");
-
- if (vip && (si.st_dev != vip->st_dev
- || si.st_ino != vip->st_ino))
- continue;
- }
-
- if (vp->tstart != old_start) {
-
- /* Once we find a relocation base address for one of the symtabs
- in this objfile, it will be the same for all symtabs in this
- objfile. Clean this algorithm. FIXME. */
-
- for (; s; s = s->next)
- if (!s->nonreloc || LINETABLE(s))
- vmap_symtab_1(s, vp, old_start);
-
-#if 0
- Himm.., recently we nullified trampoline entry names in order not
- to confuse them with real symbols. Appearently this turned into a
- problem, and msymbol vector did not get relocated properly. If
- msymbols have to have non-null names, then we should name
- trampoline entries with empty strings.
-
- ALL_MSYMBOLS (objfile, msymbol)
-#else
- for (msymbol = objfile->msymbols;
- msymbol->name || msymbol->address; (msymbol)++)
-#endif
- if (msymbol->address < TEXT_SEGMENT_BASE)
- msymbol -> address += vp->tstart - old_start;
-
- break;
- }
- }
- }
-
- if (vp->tstart != old_start) {
- /* breakpoints need to be relocated as well. */
- fixup_breakpoints (0, TEXT_SEGMENT_BASE, vp->tstart - old_start);
- }
-
- symtab_relocated = 1;
-}
-
-
-vmap_symtab_1(s, vp, old_start)
-register struct symtab *s;
-register struct vmap *vp;
-CORE_ADDR old_start;
-{
- register int i, j;
- int len, blen;
- register struct linetable *l;
- struct blockvector *bv;
- register struct block *b;
- int depth;
- register ulong reloc, dreloc;
-
- if ((reloc = vp->tstart - old_start) == 0)
- return;
-
- dreloc = vp->dstart; /* data relocation */
-
- /*
- * The line table must be relocated. This is only present for
- * .text sections, so only vp->text type maps need be considered.
- */
- l = LINETABLE (s);
- if (l) {
- len = l->nitems;
- for (i = 0; i < len; i++)
- l->item[i].pc += reloc;
- }
-
- /* if this symbol table is not relocatable, only line table should
- be relocated and the rest ignored. */
- if (s->nonreloc)
- return;
-
- bv = BLOCKVECTOR(s);
- len = BLOCKVECTOR_NBLOCKS(bv);
-
- for (i = 0; i < len; i++) {
- b = BLOCKVECTOR_BLOCK(bv, i);
-
- BLOCK_START(b) += reloc;
- BLOCK_END(b) += reloc;
-
- blen = BLOCK_NSYMS(b);
- for (j = 0; j < blen; j++) {
- register struct symbol *sym;
-
- sym = BLOCK_SYM(b, j);
- switch (SYMBOL_NAMESPACE(sym)) {
- case STRUCT_NAMESPACE:
- case UNDEF_NAMESPACE:
- continue;
-
- case LABEL_NAMESPACE:
- case VAR_NAMESPACE:
- break;
- }
-
- switch (SYMBOL_CLASS(sym)) {
- case LOC_CONST:
- case LOC_CONST_BYTES:
- case LOC_LOCAL:
- case LOC_REGISTER:
- case LOC_ARG:
- case LOC_LOCAL_ARG:
- case LOC_REF_ARG:
- case LOC_REGPARM:
- case LOC_TYPEDEF:
- continue;
-
-#ifdef FIXME
- case LOC_EXTERNAL:
-#endif
- case LOC_LABEL:
- SYMBOL_VALUE_ADDRESS(sym) += reloc;
- break;
-
- case LOC_STATIC:
- SYMBOL_VALUE_ADDRESS(sym) += dreloc;
- break;
-
- case LOC_BLOCK:
- break;
-
- default:
- fatal("botched symbol class %x"
- , SYMBOL_CLASS(sym));
- break;
- }
- }
- }
-}
-
-/*
- * add_vmap - add a new vmap entry based on ldinfo() information
- */
-add_vmap(ldi)
-register struct ld_info *ldi; {
- bfd *bfd, *last;
- register char *mem, *objname;
-
- /* This ldi structure was allocated using alloca() in
- xcoff_relocate_symtab(). Now we need to have persistent object
- and member names, so we should save them. */
-
- mem = ldi->ldinfo_filename + strlen(ldi->ldinfo_filename) + 1;
- mem = savestring (mem, strlen (mem));
- objname = savestring (ldi->ldinfo_filename, strlen (ldi->ldinfo_filename));
-
- bfd = bfd_fdopenr(objname, NULL, ldi->ldinfo_fd);
- if (!bfd)
- error("Could not open `%s' as an executable file: %s",
- objname, bfd_errmsg(bfd_error));
-
-
- /* make sure we have an object file */
-
- if (bfd_check_format(bfd, bfd_object))
- map_vmap (bfd, 0);
-
- else if (bfd_check_format(bfd, bfd_archive)) {
- last = 0;
- /*
- * FIXME??? am I tossing BFDs? bfd?
- */
- while (last = bfd_openr_next_archived_file(bfd, last))
- if (eq(mem, last->filename))
- break;
-
- if (!last) {
- bfd_close(bfd);
- /* FIXME -- should be error */
- warning("\"%s\": member \"%s\" missing.", bfd->filename, mem);
- return;
- }
-
- if (!bfd_check_format(last, bfd_object)) {
- bfd_close(last); /* XXX??? */
- goto obj_err;
- }
-
- map_vmap (last, bfd);
- }
- else {
- obj_err:
- bfd_close(bfd);
-/* FIXME -- should be error */
- warning("\"%s\": not in executable format: %s."
- , objname, bfd_errmsg(bfd_error));
- return;
- }
-}
-
-
-/* As well as symbol tables, exec_sections need relocation. After
- the inferior process' termination, there will be a relocated symbol
- table exist with no corresponding inferior process. At that time, we
- need to use `exec' bfd, rather than the inferior process's memory space
- to look up symbols.
-
- `exec_sections' need to be relocated only once, as long as the exec
- file remains unchanged.
-*/
-vmap_exec ()
-{
- static bfd *execbfd;
- int i;
-
- if (execbfd == exec_bfd)
- return;
-
- execbfd = exec_bfd;
-
- if (!vmap || !exec_ops.to_sections)
- error ("vmap_exec: vmap or exec_ops.to_sections == 0\n");
-
- for (i=0; &exec_ops.to_sections[i] < exec_ops.to_sections_end; i++)
- {
- if (strcmp(".text", exec_ops.to_sections[i].sec_ptr->name) == 0)
- {
- exec_ops.to_sections[i].addr += vmap->tstart;
- exec_ops.to_sections[i].endaddr += vmap->tstart;
- }
- else if (strcmp(".data", exec_ops.to_sections[i].sec_ptr->name) == 0)
- {
- exec_ops.to_sections[i].addr += vmap->dstart;
- exec_ops.to_sections[i].endaddr += vmap->dstart;
- }
- }
-}
-
-
-int
-text_adjustment (abfd)
-bfd *abfd;
-{
- static bfd *execbfd;
- static int adjustment;
- sec_ptr sect;
-
- if (exec_bfd == execbfd)
- return adjustment;
-
- sect = bfd_get_section_by_name (abfd, ".text");
- if (sect)
- adjustment = sect->filepos - sect->vma;
- else
- adjustment = 0x200; /* just a wild assumption */
-
- return adjustment;
-}
-
-
-/*
- * vmap_ldinfo - update VMAP info with ldinfo() information
- *
- * Input:
- * ldi - ^ to ldinfo() results.
- */
-vmap_ldinfo(ldi)
-register struct ld_info *ldi;
-{
- struct stat ii, vi;
- register struct vmap *vp;
- register got_one, retried;
- CORE_ADDR ostart;
-
- /*
- * for each *ldi, see if we have a corresponding *vp
- * if so, update the mapping, and symbol table.
- * if not, add an entry and symbol table.
- */
- do {
- char *name = ldi->ldinfo_filename;
- char *memb = name + strlen(name) + 1;
-
- retried = 0;
-
- if (fstat(ldi->ldinfo_fd, &ii) < 0)
- fatal("cannot fstat(%d) on %s"
- , ldi->ldinfo_fd
- , name);
-retry:
- for (got_one = 0, vp = vmap; vp; vp = vp->nxt) {
- FILE *io;
-
- /* First try to find a `vp', which is the same as in ldinfo.
- If not the same, just continue and grep the next `vp'. If same,
- relocate its tstart, tend, dstart, dend values. If no such `vp'
- found, get out of this for loop, add this ldi entry as a new vmap
- (add_vmap) and come back, fins its `vp' and so on... */
-
- /* The filenames are not always sufficient to match on. */
-
- if ((name[0] == "/" && !eq(name, vp->name))
- || (memb[0] && !eq(memb, vp->member)))
- continue;
-
- io = bfd_cache_lookup(vp->bfd); /* totally opaque! */
- if (!io)
- fatal("cannot find BFD's iostream for %s", vp->name);
-
- /* see if we are referring to the same file */
-
- if (fstat(fileno(io), &vi) < 0)
- fatal("cannot fstat BFD for %s", vp->name);
-
- if (ii.st_dev != vi.st_dev || ii.st_ino != vi.st_ino)
- continue;
-
- if (!retried)
- close(ldi->ldinfo_fd);
-
- ++got_one;
-
- /* found a corresponding VMAP. remap! */
- ostart = vp->tstart;
-
- vp->tstart = ldi->ldinfo_textorg;
- vp->tend = vp->tstart + ldi->ldinfo_textsize;
- vp->dstart = ldi->ldinfo_dataorg;
- vp->dend = vp->dstart + ldi->ldinfo_datasize;
-
- if (vp->tadj) {
- vp->tstart += vp->tadj;
- vp->tend += vp->tadj;
- }
-
- /* relocate symbol table(s). */
- vmap_symtab(vp, ostart, &vi);
-
- /* there may be more, so we don't break out of the loop. */
- }
-
- /* if there was no matching *vp, we must perforce create the sucker(s) */
- if (!got_one && !retried) {
- add_vmap(ldi);
- ++retried;
- goto retry;
- }
- } while (ldi->ldinfo_next
- && (ldi = (void *) (ldi->ldinfo_next + (char *) ldi)));
-
-}
-
-/*
- * vmap_inferior - print VMAP info for inferior
- */
-vmap_inferior() {
-
- if (inferior_pid == 0)
- return 0; /* normal processing */
-
- exec_files_info();
- return 1;