#include "gdbcmd.h"
#include "gdbcore.h"
#include "symfile.h"
+#include "objfiles.h"
#include "libbfd.h" /* BFD internals (sigh!) FIXME */
+#include "xcoffsolib.h"
/* Prototypes for local functions */
static void exec_files_info();
extern struct objfile *lookup_objfile_bfd ();
+#if 0
/*
* the vmap struct is used to describe the virtual address space of
* the target we are manipulating. The first entry is always the "exec"
};
static struct vmap *vmap; /* current vmap */
+#endif /* 0 */
+
+struct vmap *vmap; /* current vmap */
extern struct target_ops exec_ops;
}
vmap = 0;
- exec_bfd = 0;
+
+ if (exec_bfd) {
+ bfd_close (exec_bfd);
+ exec_bfd = NULL;
+ }
+ if (exec_ops.to_sections) {
+ free (exec_ops.to_sections);
+ exec_ops.to_sections = NULL;
+ exec_ops.to_sections_end = NULL;
+ }
}
/*
exec_file_command(filename, from_tty)
char *filename;
{
- bfd *bfd;
-
target_preopen(from_tty);
+
+ /* Remove any previous exec file. */
unpush_target(&exec_ops);
/* Now open and digest the file the user requested, if any. */
filename = tilde_expand(filename);
make_cleanup (free, filename);
- scratch_chan = openp(getenv("PATH"), 1, filename, O_RDONLY, 0
- , &scratch_pathname);
+ scratch_chan = openp(getenv("PATH"), 1, filename,
+ write_files? O_RDWR: O_RDONLY, 0,
+ &scratch_pathname);
if (scratch_chan < 0)
perror_with_name(filename);
- bfd = bfd_fdopenr(scratch_pathname, NULL, scratch_chan);
- if (!bfd)
+ exec_bfd = bfd_fdopenr(scratch_pathname, NULL, scratch_chan);
+ if (!exec_bfd)
error("Could not open `%s' as an executable file: %s"
, scratch_pathname, bfd_errmsg(bfd_error));
/* make sure we have an object file */
- if (!bfd_check_format(bfd, bfd_object))
- error("\"%s\": not in executable format: %s."
- , scratch_pathname, bfd_errmsg(bfd_error));
+ if (!bfd_check_format(exec_bfd, bfd_object))
+ error("\"%s\": not in executable format: %s.",
+ scratch_pathname, bfd_errmsg(bfd_error));
/* setup initial vmap */
- map_vmap (bfd, 0);
+ map_vmap (exec_bfd, 0);
if (!vmap)
- error("Can't find the file sections in `%s': %s"
- , bfd->filename, bfd_errmsg(bfd_error));
-
- exec_bfd = bfd;
+ error("Can't find the file sections in `%s': %s",
+ exec_bfd->filename, bfd_errmsg(bfd_error));
- if (build_section_table (exec_bfd, &exec_sections, &exec_sections_end))
+ if (build_section_table (exec_bfd, &exec_ops.to_sections,
+ &exec_ops.to_sections_end))
error ("Can't find the file sections in `%s': %s",
exec_bfd->filename, bfd_errmsg (bfd_error));
/* FIXME, we need to handle BSS segment here...it alloc's but doesn't load */
if (!(aflag & SEC_LOAD))
return;
+ if (0 == bfd_section_size (abfd, asect))
+ return;
+ (*table_pp)->bfd = abfd;
(*table_pp)->sec_ptr = asect;
(*table_pp)->addr = bfd_section_vma (abfd, asect);
(*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect);
vp->tstart = 0;
vp->tend = vp->tstart + bfd_section_size(bf, sex);
- /* This is quite a tacky way to recognize the `exec' load segment (rather
- than shared libraries. You should use `arch' instead. FIXMEmgo */
- if (!vmap)
- vp->tadj = sex->filepos - bfd_section_vma(bf, sex);
- else
- vp->tadj = 0;
+ /* When it comes to this adjustment value, in contrast to our previous
+ belief shared objects should behave the same as the main load segment.
+ This is the offset from the beginning of text section to the first
+ real instruction. */
+
+ vp->tadj = sex->filepos - bfd_section_vma(bf, sex);
}
else if (!strcmp(bfd_section_name(bf, sex), ".data")) {
struct objfile *obj;
vp = (void*) xmalloc (sizeof (*vp));
+ bzero (vp, sizeof (*vp));
vp->nxt = 0;
vp->bfd = bf;
vp->name = bfd_get_filename(arch ? arch : bf);
obj = lookup_objfile_bfd (bf);
if (exec_bfd && !obj) {
- obj = allocate_objfile (bf, bfd_get_filename (bf), 0);
+ obj = allocate_objfile (bf, 0);
+
+#if 0
+ /* This is only needed if we want to load shared libraries no matter what.
+ Since we provide the choice of incremental loading of shared objects
+ now, we do not have to load them as default anymore. */
+
syms_from_objfile (obj, 0, 0, 0);
+ new_symfile_objfile (obj, 0, 0);
+#endif
}
/* find the end of the list, and append. */
*vpp = vp;
}
-/* Called via iterate_over_msymbols to relocate minimal symbols */
-
-static PTR
-relocate_minimal_symbol (objfile, msymbol, arg1, arg2, arg3)
- struct objfile *objfile;
- struct minimal_symbol *msymbol;
- PTR arg1;
- PTR arg2;
- PTR arg3;
-{
- if (msymbol->address < TEXT_SEGMENT_BASE)
- msymbol -> address += (int) arg1;
- return (NULL);
-}
/* true, if symbol table and minimal symbol table are relocated. */
{
register struct symtab *s;
register struct objfile *objfile;
+ register struct minimal_symbol *msymbol;
/*
* for each symbol table generated from the vp->bfd
*/
- for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
+ ALL_OBJFILES (objfile)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next) {
if (fstat(fileno(io), &si) < 0)
fatal("cannot fstat BFD for sym");
- if (si.st_dev != vip->st_dev
- || si.st_ino != vip->st_ino)
+ if (vip && (si.st_dev != vip->st_dev
+ || si.st_ino != vip->st_ino))
continue;
}
- if (vp->tstart != old_start)
- vmap_symtab_1(s, vp, old_start);
+ 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) {
- (void) iterate_over_msymbols (relocate_minimal_symbol,
- (PTR) (vp->tstart - old_start),
- (PTR) NULL, (PTR) NULL);
+ 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;
add_vmap(ldi)
register struct ld_info *ldi; {
bfd *bfd, *last;
- register char *mem;
+ 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;
- bfd = bfd_fdopenr(ldi->ldinfo_filename, NULL, ldi->ldinfo_fd);
+ 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"
- , ldi->ldinfo_filename, bfd_errmsg(bfd_error));
+ 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);
+ map_vmap (bfd, 0);
else if (bfd_check_format(bfd, bfd_archive)) {
last = 0;
break;
if (!last) {
- bfd_close(bfd);
-/* FIXME -- should be error */
- warning("\"%s\": member \"%s\" missing.",
- bfd->filename, mem);
- return;
+ 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(bfd);
/* FIXME -- should be error */
warning("\"%s\": not in executable format: %s."
- , ldi->ldinfo_filename, bfd_errmsg(bfd_error));
+ , objname, bfd_errmsg(bfd_error));
return;
}
}
-/* As well as symbol tables, exec_sections need relocation. Otherwise after
- the inferior process terminates, symbol table is relocated but there is
- no inferior process. Thus, we have to use `exec' bfd, rather than the inferior
- process's memory space, when lookipng at symbols.
- `exec_sections' need to be relocated only once though, as long as the exec
- file was not changed.
+/* 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_sections) {
- printf ("WARNING: vmap not found in vmap_exec()!\n");
- return;
- }
- /* First exec section is `.text', second is `.data'. If this is changed,
- then this routine will choke. Better you should check section names,
- FIXMEmgo. */
- exec_sections [0].addr += vmap->tstart;
- exec_sections [0].endaddr += vmap->tstart;
- exec_sections [1].addr += vmap->dstart;
- exec_sections [1].endaddr += vmap->dstart;
+ 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;
+ }
+ }
}
, name);
retry:
for (got_one = 0, vp = vmap; vp; vp = vp->nxt) {
- FILE *io;
+ FILE *io;
- /* The filenames are not always sufficient to match on. */
- if ((name[0] == "/"
- && !eq(name, vp->name))
- || (memb[0] && !eq(memb, vp->member)))
- continue;
+ /* 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... */
- /* totally opaque! */
- io = bfd_cache_lookup(vp->bfd);
- if (!io)
- fatal("cannot find BFD's iostream for %s"
- , vp->name);
+ /* The filenames are not always sufficient to match on. */
- /* see if we are referring to the same file */
- if (fstat(fileno(io), &vi) < 0)
- fatal("cannot fstat BFD for %s", vp->name);
+ if ((name[0] == "/" && !eq(name, vp->name))
+ || (memb[0] && !eq(memb, vp->member)))
+ continue;
- if (ii.st_dev != vi.st_dev || ii.st_ino != vi.st_ino)
- continue;
+ io = bfd_cache_lookup(vp->bfd); /* totally opaque! */
+ if (!io)
+ fatal("cannot find BFD's iostream for %s", vp->name);
- if (!retried)
- close(ldi->ldinfo_fd);
+ /* see if we are referring to the same file */
- ++got_one;
+ if (fstat(fileno(io), &vi) < 0)
+ fatal("cannot fstat BFD for %s", vp->name);
- /* found a corresponding VMAP. remap! */
- ostart = vp->tstart;
+ if (ii.st_dev != vi.st_dev || ii.st_ino != vi.st_ino)
+ continue;
- 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 (!retried)
+ close(ldi->ldinfo_fd);
- if (vp->tadj) {
- vp->tstart += vp->tadj;
- vp->tend += vp->tadj;
- }
+ ++got_one;
+
+ /* found a corresponding VMAP. remap! */
+ ostart = vp->tstart;
- /* relocate symbol table(s). */
- vmap_symtab(vp, ostart, &vi);
+ vp->tstart = ldi->ldinfo_textorg;
+ vp->tend = vp->tstart + ldi->ldinfo_textsize;
+ vp->dstart = ldi->ldinfo_dataorg;
+ vp->dend = vp->dstart + ldi->ldinfo_datasize;
- /* there may be more, so we don't break out of the loop. */
+ 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;
+ /* 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() {
if (inferior_pid == 0)
- return 0; /* normal processing */
+ return 0; /* normal processing */
exec_files_info();
-
return 1;
}
struct target_ops *t;
bfd *abfd;
{
-#if 1
struct section_table *p;
printf_filtered ("\t`%s', ", bfd_get_filename(abfd));
}
printf_filtered ("\n");
}
-#else
- register struct vmap *vp = vmap;
-
- if (!vp)
- return;
-
- printf("\tMapping info for file `%s'.\n", vp->name);
- printf("\t %8.8s %8.8s %8.8s %s\n"
- , "start", "end", "section", "file(member)");
-
- for (; vp; vp = vp->nxt)
- printf("\t0x%8.8x 0x%8.8x %s%s%s%s\n"
- , vp->tstart
- , vp->tend
- , vp->name
- , *vp->member ? "(" : ""
- , vp->member
- , *vp->member ? ")" : "");
-#endif
}
+
static void
exec_files_info (t)
struct target_ops *t;
{
+ register struct vmap *vp = vmap;
+
print_section_info (t, exec_bfd);
+
+ if (!vp)
+ return;
+
+ printf("\tMapping info for file `%s'.\n", vp->name);
+
+ printf("\t %8.8s %8.8s %8.8s %8.8s %8.8s %s\n",
+ "tstart", "tend", "dstart", "dend", "section", "file(member)");
+
+ for (; vp; vp = vp->nxt)
+ printf("\t0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x %s%s%s%s\n",
+ vp->tstart,
+ vp->tend,
+ vp->dstart,
+ vp->dend,
+ vp->name,
+ *vp->member ? "(" : "",
+ vp->member,
+ *vp->member ? ")" : "");
}
#ifdef DAMON
/* Parse out new virtual address */
secaddr = parse_and_eval_address (args);
- for (p = exec_sections; p < exec_sections_end; p++) {
+ for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++) {
if (!strncmp (secname, bfd_section_name (exec_bfd, p->sec_ptr), seclen)
&& bfd_section_name (exec_bfd, p->sec_ptr)[seclen] == '\0') {
offset = secaddr - p->addr;
p->addr += offset;
p->endaddr += offset;
- exec_files_info();
+ if (from_tty)
+ exec_files_info(&exec_ops);
return;
}
}