1 /* Execute AIXcoff files, for GDB.
2 Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
3 Derived from exec.c. Modified by IBM Corporation.
4 Donated by IBM Corporation and Cygnus Support.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* xcoff-exec - deal with executing XCOFF files. */
26 #include <sys/types.h>
27 #include <sys/param.h>
42 #include "libbfd.h" /* BFD internals (sigh!) FIXME */
44 #include "xcoffsolib.h"
46 /* Prototypes for local functions */
49 file_command PARAMS ((char *, int));
52 exec_close PARAMS ((int));
55 map_vmap PARAMS ((bfd *, bfd *));
57 struct section_table *exec_sections, *exec_sections_end;
59 /* Whether to open exec and core files read-only or read-write. */
63 extern int info_verbose;
65 bfd *exec_bfd; /* needed by core.c */
67 extern char *getenv();
68 extern void add_syms_addr_command ();
69 extern void symbol_file_command ();
70 static void exec_files_info();
72 struct vmap *vmap; /* current vmap */
74 extern struct target_ops exec_ops;
77 /* exec_close - done with exec file, clean up all resources. */
82 register struct vmap *vp, *nxt;
85 for (nxt = vmap; vp = nxt; )
89 /* if there is an objfile associated with this bfd,
90 free_objfile() will do proper cleanup of objfile *and* bfd. */
93 free_objfile (vp->objfile);
97 /* FIXME: This routine is #if 0'd in symfile.c. What should we
98 be doing here? Should we just free everything in
99 vp->objfile->symtabs? Should free_objfile do that? */
100 free_named_symtabs(vp->name);
106 /* exec_bfd was already closed (the exec file has a vmap entry). */
109 if (exec_ops.to_sections) {
110 free (exec_ops.to_sections);
111 exec_ops.to_sections = NULL;
112 exec_ops.to_sections_end = NULL;
117 * exec_file_command - handle the "exec" command, &c.
120 exec_file_command(filename, from_tty)
123 target_preopen(from_tty);
125 /* Remove any previous exec file. */
126 unpush_target(&exec_ops);
128 /* Now open and digest the file the user requested, if any. */
131 char *scratch_pathname;
134 filename = tilde_expand(filename);
135 make_cleanup (free, filename);
137 scratch_chan = openp(getenv("PATH"), 1, filename,
138 write_files? O_RDWR: O_RDONLY, 0,
140 if (scratch_chan < 0)
141 perror_with_name(filename);
143 exec_bfd = bfd_fdopenr(scratch_pathname, NULL, scratch_chan);
145 error("Could not open `%s' as an executable file: %s"
146 , scratch_pathname, bfd_errmsg(bfd_error));
148 /* make sure we have an object file */
150 if (!bfd_check_format(exec_bfd, bfd_object))
151 error("\"%s\": not in executable format: %s.",
152 scratch_pathname, bfd_errmsg(bfd_error));
155 /* setup initial vmap */
157 map_vmap (exec_bfd, 0);
159 error("Can't find the file sections in `%s': %s",
160 exec_bfd->filename, bfd_errmsg(bfd_error));
162 if (build_section_table (exec_bfd, &exec_ops.to_sections,
163 &exec_ops.to_sections_end))
164 error ("Can't find the file sections in `%s': %s",
165 exec_bfd->filename, bfd_errmsg (bfd_error));
167 /* make sure core, if present, matches */
170 push_target(&exec_ops);
172 /* Tell display code(if any) about the changed file name. */
174 if (exec_file_display_hook)
175 (*exec_file_display_hook)(filename);
178 exec_close(0); /* just in case */
180 printf("No exec file now.\n");
184 /* Set both the exec file and the symbol file, in one command. What a
185 * novelty. Why did GDB go through four major releases before this
189 file_command(arg, from_tty)
192 exec_file_command(arg, from_tty);
193 symbol_file_command(arg, from_tty);
196 /* Locate all mappable sections of a BFD file.
197 table_pp_char is a char * to get it through bfd_map_over_sections;
198 we cast it back to its proper type. */
201 add_to_section_table (abfd, asect, table_pp_char)
206 struct section_table **table_pp = (struct section_table **)table_pp_char;
209 aflag = bfd_get_section_flags (abfd, asect);
210 /* FIXME, we need to handle BSS segment here...it alloc's but doesn't load */
211 if (!(aflag & SEC_LOAD))
213 if (0 == bfd_section_size (abfd, asect))
215 (*table_pp)->bfd = abfd;
216 (*table_pp)->sec_ptr = asect;
217 (*table_pp)->addr = bfd_section_vma (abfd, asect);
218 (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect);
223 build_section_table (some_bfd, start, end)
225 struct section_table **start, **end;
229 count = bfd_count_sections (some_bfd);
231 fatal ("aborting"); /* return 1? */
234 *start = (struct section_table *) xmalloc (count * sizeof (**start));
236 bfd_map_over_sections (some_bfd, add_to_section_table, (char *)end);
237 if (*end > *start + count)
239 /* We could realloc the table, but it probably loses for most files. */
244 sex_to_vmap(bfd *bf, sec_ptr sex, PTR arg3)
246 struct vmap_and_bfd *vmap_bfd = (struct vmap_and_bfd *)arg3;
247 register struct vmap *vp, **vpp;
248 register struct symtab *syms;
249 bfd *arch = vmap_bfd->pbfd;
250 vp = vmap_bfd->pvmap;
252 if ((bfd_get_section_flags(bf, sex) & SEC_LOAD) == 0)
255 if (STREQ(bfd_section_name(bf, sex), ".text")) {
257 vp->tend = vp->tstart + bfd_section_size(bf, sex);
259 /* When it comes to this adjustment value, in contrast to our previous
260 belief shared objects should behave the same as the main load segment.
261 This is the offset from the beginning of text section to the first
264 vp->tadj = sex->filepos - bfd_section_vma(bf, sex);
267 else if (STREQ(bfd_section_name(bf, sex), ".data")) {
269 vp->dend = vp->dstart + bfd_section_size(bf, sex);
272 else if (STREQ(bfd_section_name(bf, sex), ".bss")) /* FIXMEmgo */
273 printf ("bss section in exec! Don't know what the heck to do!\n");
276 /* Make a vmap for the BFD "bf", which might be a member of the archive
277 BFD "arch". Return the new vmap. */
279 map_vmap (bfd *bf, bfd *arch)
281 struct vmap_and_bfd vmap_bfd;
282 struct vmap *vp, **vpp;
285 vp = (void*) xmalloc (sizeof (*vp));
286 bzero (vp, sizeof (*vp));
289 vp->name = bfd_get_filename(arch ? arch : bf);
290 vp->member = arch ? bfd_get_filename(bf) : "";
292 vmap_bfd.pbfd = arch;
294 bfd_map_over_sections (bf, sex_to_vmap, &vmap_bfd);
296 /* find the end of the list, and append. */
297 for (vpp = &vmap; *vpp; vpp = &(*vpp)->nxt)
305 /* vmap_symtab - handle symbol translation on vmapping */
309 register struct vmap *vp;
311 register struct objfile *objfile;
315 CORE_ADDR text_delta;
316 CORE_ADDR data_delta;
318 struct section_offsets *new_offsets;
321 objfile = vp->objfile;
324 /* OK, it's not an objfile we opened ourselves.
325 Currently, that can only happen with the exec file, so
326 relocate the symbols for the symfile. */
327 if (symfile_objfile == NULL)
329 objfile = symfile_objfile;
333 (sizeof (struct section_offsets)
334 + sizeof (new_offsets->offsets) * objfile->num_sections);
336 for (i = 0; i < objfile->num_sections; ++i)
337 ANOFFSET (new_offsets, i) = ANOFFSET (objfile->section_offsets, i);
339 textsec = bfd_get_section_by_name (vp->bfd, ".text");
341 vp->tstart - ANOFFSET (objfile->section_offsets, textsec->target_index);
342 ANOFFSET (new_offsets, textsec->target_index) = vp->tstart;
344 datasec = bfd_get_section_by_name (vp->bfd, ".data");
346 vp->dstart - ANOFFSET (objfile->section_offsets, datasec->target_index);
347 ANOFFSET (new_offsets, datasec->target_index) = vp->dstart;
349 bsssec = bfd_get_section_by_name (vp->bfd, ".bss");
351 vp->dstart - ANOFFSET (objfile->section_offsets, bsssec->target_index);
352 ANOFFSET (new_offsets, bsssec->target_index) = vp->dstart;
354 objfile_relocate (objfile, new_offsets);
357 struct obj_section *s;
358 for (s = objfile->sections; s < objfile->sections_end; ++s)
360 if (s->sec_ptr->target_index == textsec->target_index)
362 s->addr += text_delta;
363 s->endaddr += text_delta;
365 else if (s->sec_ptr->target_index == datasec->target_index)
367 s->addr += data_delta;
368 s->endaddr += data_delta;
370 else if (s->sec_ptr->target_index == bsssec->target_index)
372 s->addr += bss_delta;
373 s->endaddr += bss_delta;
379 /* breakpoints need to be relocated as well. */
380 fixup_breakpoints (0, TEXT_SEGMENT_BASE, text_delta);
383 /* Add symbols for an objfile. */
385 objfile_symbol_add (arg)
388 struct objfile *obj = (struct objfile *) arg;
389 syms_from_objfile (obj, 0, 0, 0);
390 new_symfile_objfile (obj, 0, 0);
394 static struct vmap *add_vmap PARAMS ((struct ld_info *));
396 /* Add a new vmap entry based on ldinfo() information.
398 If ldi->ldinfo_fd is not valid (e.g. this struct ld_info is from a
399 core file), the caller should set it to -1, and we will open the file.
401 Return the vmap new entry. */
404 register struct ld_info *ldi;
407 register char *mem, *objname;
411 /* This ldi structure was allocated using alloca() in
412 xcoff_relocate_symtab(). Now we need to have persistent object
413 and member names, so we should save them. */
415 mem = ldi->ldinfo_filename + strlen(ldi->ldinfo_filename) + 1;
416 mem = savestring (mem, strlen (mem));
417 objname = savestring (ldi->ldinfo_filename, strlen (ldi->ldinfo_filename));
419 if (ldi->ldinfo_fd < 0)
420 /* Note that this opens it once for every member; a possible
421 enhancement would be to only open it once for every object. */
422 bfd = bfd_openr (objname, NULL);
424 bfd = bfd_fdopenr(objname, NULL, ldi->ldinfo_fd);
426 error("Could not open `%s' as an executable file: %s",
427 objname, bfd_errmsg(bfd_error));
430 /* make sure we have an object file */
432 if (bfd_check_format(bfd, bfd_object))
433 vp = map_vmap (bfd, 0);
435 else if (bfd_check_format(bfd, bfd_archive)) {
438 * FIXME??? am I tossing BFDs? bfd?
440 while (last = bfd_openr_next_archived_file(bfd, last))
441 if (STREQ(mem, last->filename))
446 /* FIXME -- should be error */
447 warning("\"%s\": member \"%s\" missing.", bfd->filename, mem);
451 if (!bfd_check_format(last, bfd_object)) {
452 bfd_close(last); /* XXX??? */
456 vp = map_vmap (last, bfd);
461 error ("\"%s\": not in executable format: %s.",
462 objname, bfd_errmsg(bfd_error));
465 obj = allocate_objfile (vp->bfd, 0);
468 #ifndef SOLIB_SYMBOLS_MANUAL
469 if (catch_errors (objfile_symbol_add, (char *)obj,
470 "Error while reading shared library symbols:\n"))
472 /* Note this is only done if symbol reading was successful. */
481 /* As well as symbol tables, exec_sections need relocation. After
482 the inferior process' termination, there will be a relocated symbol
483 table exist with no corresponding inferior process. At that time, we
484 need to use `exec' bfd, rather than the inferior process's memory space
487 `exec_sections' need to be relocated only once, as long as the exec
488 file remains unchanged.
495 if (execbfd == exec_bfd)
500 if (!vmap || !exec_ops.to_sections)
501 error ("vmap_exec: vmap or exec_ops.to_sections == 0\n");
503 for (i=0; &exec_ops.to_sections[i] < exec_ops.to_sections_end; i++)
505 if (STREQ(".text", exec_ops.to_sections[i].sec_ptr->name))
507 exec_ops.to_sections[i].addr += vmap->tstart;
508 exec_ops.to_sections[i].endaddr += vmap->tstart;
510 else if (STREQ(".data", exec_ops.to_sections[i].sec_ptr->name))
512 exec_ops.to_sections[i].addr += vmap->dstart;
513 exec_ops.to_sections[i].endaddr += vmap->dstart;
519 /* This was for the old, half-assed, core file support. */
521 text_adjustment (abfd)
525 static int adjustment;
528 if (exec_bfd == execbfd)
531 sect = bfd_get_section_by_name (abfd, ".text");
533 adjustment = sect->filepos - sect->vma;
535 adjustment = 0x200; /* just a wild assumption */
542 * vmap_ldinfo - update VMAP info with ldinfo() information
545 * ldi - ^ to ldinfo() results.
548 register struct ld_info *ldi;
551 register struct vmap *vp;
552 register got_one, retried;
556 * for each *ldi, see if we have a corresponding *vp
557 * if so, update the mapping, and symbol table.
558 * if not, add an entry and symbol table.
561 char *name = ldi->ldinfo_filename;
562 char *memb = name + strlen(name) + 1;
566 if (fstat(ldi->ldinfo_fd, &ii) < 0)
567 fatal("cannot fstat(%d) on %s"
571 for (got_one = 0, vp = vmap; vp; vp = vp->nxt) {
574 /* First try to find a `vp', which is the same as in ldinfo.
575 If not the same, just continue and grep the next `vp'. If same,
576 relocate its tstart, tend, dstart, dend values. If no such `vp'
577 found, get out of this for loop, add this ldi entry as a new vmap
578 (add_vmap) and come back, fins its `vp' and so on... */
580 /* The filenames are not always sufficient to match on. */
582 if ((name[0] == '/' && !STREQ(name, vp->name))
583 || (memb[0] && !STREQ(memb, vp->member)))
586 io = bfd_cache_lookup(vp->bfd); /* totally opaque! */
588 fatal("cannot find BFD's iostream for %s", vp->name);
590 /* see if we are referring to the same file */
592 if (fstat(fileno(io), &vi) < 0)
593 fatal("cannot fstat BFD for %s", vp->name);
595 if (ii.st_dev != vi.st_dev || ii.st_ino != vi.st_ino)
599 close(ldi->ldinfo_fd);
603 /* found a corresponding VMAP. remap! */
606 /* We can assume pointer == CORE_ADDR, this code is native only. */
607 vp->tstart = (CORE_ADDR) ldi->ldinfo_textorg;
608 vp->tend = vp->tstart + ldi->ldinfo_textsize;
609 vp->dstart = (CORE_ADDR) ldi->ldinfo_dataorg;
610 vp->dend = vp->dstart + ldi->ldinfo_datasize;
613 vp->tstart += vp->tadj;
614 vp->tend += vp->tadj;
617 /* relocate symbol table(s). */
620 /* there may be more, so we don't break out of the loop. */
623 /* if there was no matching *vp, we must perforce create the sucker(s) */
624 if (!got_one && !retried) {
629 } while (ldi->ldinfo_next
630 && (ldi = (void *) (ldi->ldinfo_next + (char *) ldi)));
635 * vmap_inferior - print VMAP info for inferior
639 if (inferior_pid == 0)
640 return 0; /* normal processing */
646 /* Read or write the exec file.
648 Args are address within exec file, address within gdb address-space,
649 length, and a flag indicating whether to read or write.
653 0: We cannot handle this address and length.
654 > 0: We have handled N bytes starting at this address.
655 (If N == length, we did it all.) We might be able
656 to handle more bytes beyond this length, but no
658 < 0: We cannot handle this address, but if somebody
659 else handles (-N) bytes, we can start from there.
661 The same routine is used to handle both core and exec files;
662 we just tail-call it with more arguments to select between them. */
665 xfer_memory (memaddr, myaddr, len, write, target)
670 struct target_ops *target;
673 struct section_table *p;
674 CORE_ADDR nextsectaddr, memend;
675 boolean (*xfer_fn) PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
680 memend = memaddr + len;
681 xfer_fn = write? bfd_set_section_contents: bfd_get_section_contents;
682 nextsectaddr = memend;
684 for (p = target->to_sections; p < target->to_sections_end; p++)
686 if (p->addr <= memaddr)
687 if (p->endaddr >= memend)
689 /* Entire transfer is within this section. */
690 res = xfer_fn (p->bfd, p->sec_ptr, myaddr, memaddr - p->addr, len);
691 return (res != false)? len: 0;
693 else if (p->endaddr <= memaddr)
695 /* This section ends before the transfer starts. */
700 /* This section overlaps the transfer. Just do half. */
701 len = p->endaddr - memaddr;
702 res = xfer_fn (p->bfd, p->sec_ptr, myaddr, memaddr - p->addr, len);
703 return (res != false)? len: 0;
705 else if (p->addr < nextsectaddr)
706 nextsectaddr = p->addr;
709 if (nextsectaddr >= memend)
710 return 0; /* We can't help */
712 return - (nextsectaddr - memaddr); /* Next boundary where we can help */
716 print_section_info (t, abfd)
717 struct target_ops *t;
720 struct section_table *p;
722 printf_filtered ("\t`%s', ", bfd_get_filename(abfd));
724 printf_filtered ("file type %s.\n", bfd_get_target(abfd));
726 for (p = t->to_sections; p < t->to_sections_end; p++) {
727 printf_filtered ("\t%s", local_hex_string_custom (p->addr, "08"));
728 printf_filtered (" - %s", local_hex_string_custom (p->endaddr, "08"));
730 printf_filtered (" @ %s",
731 local_hex_string_custom (p->sec_ptr->filepos, "08"));
732 printf_filtered (" is %s", bfd_section_name (p->bfd, p->sec_ptr));
733 if (p->bfd != abfd) {
734 printf_filtered (" in %s", bfd_get_filename (p->bfd));
736 printf_filtered ("\n");
743 struct target_ops *t;
745 register struct vmap *vp = vmap;
747 print_section_info (t, exec_bfd);
752 printf("\tMapping info for file `%s'.\n", vp->name);
754 printf("\t %8.8s %8.8s %8.8s %8.8s %8.8s %s\n",
755 "tstart", "tend", "dstart", "dend", "section", "file(member)");
757 for (; vp; vp = vp->nxt)
758 printf("\t0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x %s%s%s%s\n",
764 *vp->member ? "(" : "",
766 *vp->member ? ")" : "");
770 /* Damon's implementation of set_section_command! It is based on the sex member
771 (which is a section pointer from vmap) of vmap.
772 We will not have multiple vmap entries (one for each section), rather transmit
773 text and data base offsets and fix them at the same time. Elimination of sex
774 entry in vmap make this function obsolute, use the one from exec.c.
775 Need further testing!! FIXMEmgo. */
778 set_section_command(args, from_tty)
781 register struct vmap *vp = vmap;
784 unsigned long secaddr;
789 error("Must specify section name and its virtual address");
791 /* Parse out section name */
792 for (secname = args; !isspace(*args); args++)
794 seclen = args - secname;
796 /* Parse out new virtual address */
797 secaddr = parse_and_eval_address(args);
799 for (vp = vmap; vp; vp = vp->nxt) {
801 , bfd_section_name(vp->bfd, vp->sex), seclen)
802 && bfd_section_name(vp->bfd, vp->sex)[seclen] == '\0') {
803 offset = secaddr - vp->tstart;
804 vp->tstart += offset;
811 if (seclen >= sizeof(secprint))
812 seclen = sizeof(secprint) - 1;
813 strncpy(secprint, secname, seclen);
814 secprint[seclen] = '\0';
815 error("Section %s not found", secprint);
819 set_section_command (args, from_tty)
823 struct section_table *p;
826 unsigned long secaddr;
831 error ("Must specify section name and its virtual address");
833 /* Parse out section name */
834 for (secname = args; !isspace(*args); args++) ;
835 seclen = args - secname;
837 /* Parse out new virtual address */
838 secaddr = parse_and_eval_address (args);
840 for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++) {
841 if (!strncmp (secname, bfd_section_name (exec_bfd, p->sec_ptr), seclen)
842 && bfd_section_name (exec_bfd, p->sec_ptr)[seclen] == '\0') {
843 offset = secaddr - p->addr;
845 p->endaddr += offset;
847 exec_files_info(&exec_ops);
851 if (seclen >= sizeof (secprint))
852 seclen = sizeof (secprint) - 1;
853 strncpy (secprint, secname, seclen);
854 secprint[seclen] = '\0';
855 error ("Section %s not found", secprint);
860 struct target_ops exec_ops = {
861 "exec", "Local exec file",
862 "Use an executable file as a target.\n\
863 Specify the filename of the executable file.",
864 exec_file_command, exec_close, /* open, close */
865 find_default_attach, 0, 0, 0, /* attach, detach, resume, wait, */
866 0, 0, /* fetch_registers, store_registers, */
867 0, /* prepare_to_store */
868 xfer_memory, exec_files_info,
869 0, 0, /* insert_breakpoint, remove_breakpoint, */
870 0, 0, 0, 0, 0, /* terminal stuff */
871 0, 0, /* kill, load */
873 find_default_create_inferior,
874 0, /* mourn_inferior */
876 0, /* notice_signals */
877 file_stratum, 0, /* next */
878 0, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */
879 0, 0, /* section pointers */
880 OPS_MAGIC, /* Always the last thing */
883 /* Core file stuff. */
885 /* Relocate symtabs and read in shared library info, based on symbols
886 from the core file. */
888 xcoff_relocate_core ()
890 /* Offset of member MEMBER in a struct of type TYPE. */
892 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
895 /* Size of a struct ld_info except for the variable-length filename. */
896 #define LDINFO_SIZE (offsetof (struct ld_info, ldinfo_filename))
900 struct ld_info *ldip;
903 /* Allocated size of buffer. */
904 int buffer_size = LDINFO_SIZE;
905 char *buffer = xmalloc (buffer_size);
906 struct cleanup *old = make_cleanup (free_current_contents, &buffer);
908 /* FIXME, this restriction should not exist. For now, though I'll
909 avoid coredumps with error() pending a real fix. */
912 ("Can't debug a core file without an executable file (on the RS/6000)");
914 ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo");
915 if (ldinfo_sec == NULL)
918 fprintf_filtered (stderr, "Couldn't get ldinfo from core file: %s\n",
919 bfd_errmsg (bfd_error));
928 /* Read in everything but the name. */
929 if (bfd_get_section_contents (core_bfd, ldinfo_sec, buffer,
930 offset, LDINFO_SIZE) == 0)
937 if (i == buffer_size)
940 buffer = xrealloc (buffer, buffer_size);
942 if (bfd_get_section_contents (core_bfd, ldinfo_sec, &buffer[i],
945 if (buffer[i++] == '\0')
947 } while (names_found < 2);
949 ldip = (struct ld_info *)buffer;
951 /* Can't use a file descriptor from the core file; need to open it. */
952 ldip->ldinfo_fd = -1;
954 /* The first ldinfo is for the exec file, allocated elsewhere. */
958 vp = add_vmap (ldip);
960 offset += ldip->ldinfo_next;
962 /* We can assume pointer == CORE_ADDR, this code is native only. */
963 vp->tstart = (CORE_ADDR) ldip->ldinfo_textorg;
964 vp->tend = vp->tstart + ldip->ldinfo_textsize;
965 vp->dstart = (CORE_ADDR) ldip->ldinfo_dataorg;
966 vp->dend = vp->dstart + ldip->ldinfo_datasize;
969 vp->tstart += vp->tadj;
970 vp->tend += vp->tadj;
973 /* Unless this is the exec file,
974 add our sections to the section table for the core target. */
978 struct section_table *stp;
980 count = core_ops.to_sections_end - core_ops.to_sections;
982 core_ops.to_sections = (struct section_table *)
983 xrealloc (core_ops.to_sections,
984 sizeof (struct section_table) * count);
985 core_ops.to_sections_end = core_ops.to_sections + count;
986 stp = core_ops.to_sections_end - 2;
988 /* "Why do we add bfd_section_vma?", I hear you cry.
989 Well, the start of the section in the file is actually
990 that far into the section as the struct vmap understands it.
991 So for text sections, bfd_section_vma tends to be 0x200,
992 and if vp->tstart is 0xd0002000, then the first byte of
993 the text section on disk corresponds to address 0xd0002200. */
995 stp->sec_ptr = bfd_get_section_by_name (stp->bfd, ".text");
996 stp->addr = bfd_section_vma (stp->bfd, stp->sec_ptr) + vp->tstart;
997 stp->endaddr = bfd_section_vma (stp->bfd, stp->sec_ptr) + vp->tend;
1001 stp->sec_ptr = bfd_get_section_by_name (stp->bfd, ".data");
1002 stp->addr = bfd_section_vma (stp->bfd, stp->sec_ptr) + vp->dstart;
1003 stp->endaddr = bfd_section_vma (stp->bfd, stp->sec_ptr) + vp->dend;
1008 add_text_to_loadinfo ((CORE_ADDR)ldip->ldinfo_textorg,
1009 (CORE_ADDR)ldip->ldinfo_dataorg);
1010 } while (ldip->ldinfo_next != 0);
1019 add_com("file", class_files, file_command,
1020 "Use FILE as program to be debugged.\n\
1021 It is read for its symbols, for getting the contents of pure memory,\n\
1022 and it is the program executed when you use the `run' command.\n\
1023 If FILE cannot be found as specified, your execution directory path\n\
1024 ($PATH) is searched for a command of that name.\n\
1025 No arg means to have no executable file and no symbols.");
1027 add_com("exec-file", class_files, exec_file_command,
1028 "Use FILE as program for getting contents of pure memory.\n\
1029 If FILE cannot be found as specified, your execution directory path\n\
1030 is searched for a command of that name.\n\
1031 No arg means have no executable file.");
1033 add_com("section", class_files, set_section_command,
1034 "Change the base address of section SECTION of the exec file to ADDR.\n\
1035 This can be used if the exec file does not contain section addresses,\n\
1036 (such as in the a.out format), or when the addresses specified in the\n\
1037 file itself are wrong. Each section must be changed separately. The\n\
1038 ``info files'' command lists all the sections and their addresses.");
1040 add_target(&exec_ops);