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
);
107 bfd_close (exec_bfd
);
110 if (exec_ops
.to_sections
) {
111 free (exec_ops
.to_sections
);
112 exec_ops
.to_sections
= NULL
;
113 exec_ops
.to_sections_end
= NULL
;
118 * exec_file_command - handle the "exec" command, &c.
121 exec_file_command(filename
, from_tty
)
124 target_preopen(from_tty
);
126 /* Remove any previous exec file. */
127 unpush_target(&exec_ops
);
129 /* Now open and digest the file the user requested, if any. */
132 char *scratch_pathname
;
135 filename
= tilde_expand(filename
);
136 make_cleanup (free
, filename
);
138 scratch_chan
= openp(getenv("PATH"), 1, filename
,
139 write_files
? O_RDWR
: O_RDONLY
, 0,
141 if (scratch_chan
< 0)
142 perror_with_name(filename
);
144 exec_bfd
= bfd_fdopenr(scratch_pathname
, NULL
, scratch_chan
);
146 error("Could not open `%s' as an executable file: %s"
147 , scratch_pathname
, bfd_errmsg(bfd_error
));
149 /* make sure we have an object file */
151 if (!bfd_check_format(exec_bfd
, bfd_object
))
152 error("\"%s\": not in executable format: %s.",
153 scratch_pathname
, bfd_errmsg(bfd_error
));
156 /* setup initial vmap */
158 map_vmap (exec_bfd
, 0);
160 error("Can't find the file sections in `%s': %s",
161 exec_bfd
->filename
, bfd_errmsg(bfd_error
));
163 if (build_section_table (exec_bfd
, &exec_ops
.to_sections
,
164 &exec_ops
.to_sections_end
))
165 error ("Can't find the file sections in `%s': %s",
166 exec_bfd
->filename
, bfd_errmsg (bfd_error
));
168 /* make sure core, if present, matches */
171 push_target(&exec_ops
);
173 /* Tell display code(if any) about the changed file name. */
175 if (exec_file_display_hook
)
176 (*exec_file_display_hook
)(filename
);
179 exec_close(0); /* just in case */
181 printf("No exec file now.\n");
185 /* Set both the exec file and the symbol file, in one command. What a
186 * novelty. Why did GDB go through four major releases before this
190 file_command(arg
, from_tty
)
193 exec_file_command(arg
, from_tty
);
194 symbol_file_command(arg
, from_tty
);
197 /* Locate all mappable sections of a BFD file.
198 table_pp_char is a char * to get it through bfd_map_over_sections;
199 we cast it back to its proper type. */
202 add_to_section_table (abfd
, asect
, table_pp_char
)
207 struct section_table
**table_pp
= (struct section_table
**)table_pp_char
;
210 aflag
= bfd_get_section_flags (abfd
, asect
);
211 /* FIXME, we need to handle BSS segment here...it alloc's but doesn't load */
212 if (!(aflag
& SEC_LOAD
))
214 if (0 == bfd_section_size (abfd
, asect
))
216 (*table_pp
)->bfd
= abfd
;
217 (*table_pp
)->sec_ptr
= asect
;
218 (*table_pp
)->addr
= bfd_section_vma (abfd
, asect
);
219 (*table_pp
)->endaddr
= (*table_pp
)->addr
+ bfd_section_size (abfd
, asect
);
224 build_section_table (some_bfd
, start
, end
)
226 struct section_table
**start
, **end
;
230 count
= bfd_count_sections (some_bfd
);
232 abort(); /* return 1? */
235 *start
= (struct section_table
*) xmalloc (count
* sizeof (**start
));
237 bfd_map_over_sections (some_bfd
, add_to_section_table
, (char *)end
);
238 if (*end
> *start
+ count
)
240 /* We could realloc the table, but it probably loses for most files. */
245 sex_to_vmap(bfd
*bf
, sec_ptr sex
, struct vmap_and_bfd
*vmap_bfd
)
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 /* true, if symbol table and minimal symbol table are relocated. */
307 int symtab_relocated
= 0;
310 /* vmap_symtab - handle symbol translation on vmapping */
312 vmap_symtab(vp
, old_start
, vip
)
313 register struct vmap
*vp
;
317 register struct symtab
*s
;
318 register struct objfile
*objfile
;
319 register struct minimal_symbol
*msymbol
;
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
;
332 s
= objfile
->symtabs
;
334 if (vp
->tstart
!= old_start
) {
336 /* Once we find a relocation base address for one of the symtabs
337 in this objfile, it will be the same for all symtabs in this
338 objfile. Clean this algorithm. FIXME. */
340 for (; s
; s
= s
->next
)
341 if (!s
->nonreloc
|| LINETABLE(s
))
342 vmap_symtab_1(s
, vp
, old_start
);
345 /* I believe trampoline entries now have a name like
346 <trampoline>. In any event, if something needs to be changed,
347 it should be changed in ALL_MSYMBOLS, so it works everywhere. */
349 Himm.., recently we nullified trampoline entry names in order not
350 to confuse them with real symbols. Appearently this turned into a
351 problem, and msymbol vector did not get relocated properly. If
352 msymbols have to have non-null names, then we should name
353 trampoline entries with empty strings. */
355 ALL_MSYMBOLS (objfile
, msymbol
)
357 for (msymbol
= objfile
->msymbols
;
358 SYMBOL_NAME (msymbol
) || SYMBOL_VALUE_ADDRESS (msymbol
);
361 if (SYMBOL_VALUE_ADDRESS (msymbol
) < TEXT_SEGMENT_BASE
)
362 SYMBOL_VALUE_ADDRESS (msymbol
) += vp
->tstart
- old_start
;
366 if (vp
->tstart
!= old_start
) {
367 /* breakpoints need to be relocated as well. */
368 fixup_breakpoints (0, TEXT_SEGMENT_BASE
, vp
->tstart
- old_start
);
371 symtab_relocated
= 1;
375 vmap_symtab_1(s
, vp
, old_start
)
376 register struct symtab
*s
;
377 register struct vmap
*vp
;
382 register struct linetable
*l
;
383 struct blockvector
*bv
;
384 register struct block
*b
;
386 register ulong reloc
, dreloc
;
388 if ((reloc
= vp
->tstart
- old_start
) == 0)
391 dreloc
= vp
->dstart
; /* data relocation */
394 * The line table must be relocated. This is only present for
395 * .text sections, so only vp->text type maps need be considered.
400 for (i
= 0; i
< len
; i
++)
401 l
->item
[i
].pc
+= reloc
;
404 /* if this symbol table is not relocatable, only line table should
405 be relocated and the rest ignored. */
410 len
= BLOCKVECTOR_NBLOCKS(bv
);
412 for (i
= 0; i
< len
; i
++) {
413 b
= BLOCKVECTOR_BLOCK(bv
, i
);
415 BLOCK_START(b
) += reloc
;
416 BLOCK_END(b
) += reloc
;
418 blen
= BLOCK_NSYMS(b
);
419 for (j
= 0; j
< blen
; j
++) {
420 register struct symbol
*sym
;
422 sym
= BLOCK_SYM(b
, j
);
423 switch (SYMBOL_NAMESPACE(sym
)) {
424 case STRUCT_NAMESPACE
:
425 case UNDEF_NAMESPACE
:
428 case LABEL_NAMESPACE
:
433 switch (SYMBOL_CLASS(sym
)) {
435 case LOC_CONST_BYTES
:
449 SYMBOL_VALUE_ADDRESS(sym
) += reloc
;
453 SYMBOL_VALUE_ADDRESS(sym
) += dreloc
;
460 fatal("botched symbol class %x"
461 , SYMBOL_CLASS(sym
));
468 static struct vmap
*add_vmap
PARAMS ((struct ld_info
*));
470 /* Add a new vmap entry based on ldinfo() information.
472 If ldi->ldinfo_fd is not valid (e.g. this struct ld_info is from a
473 core file), the caller should set it to -1, and we will open the file.
475 Return the vmap new entry. */
478 register struct ld_info
*ldi
;
481 register char *mem
, *objname
;
485 /* This ldi structure was allocated using alloca() in
486 xcoff_relocate_symtab(). Now we need to have persistent object
487 and member names, so we should save them. */
489 mem
= ldi
->ldinfo_filename
+ strlen(ldi
->ldinfo_filename
) + 1;
490 mem
= savestring (mem
, strlen (mem
));
491 objname
= savestring (ldi
->ldinfo_filename
, strlen (ldi
->ldinfo_filename
));
493 if (ldi
->ldinfo_fd
< 0)
494 /* Note that this opens it once for every member; a possible
495 enhancement would be to only open it once for every object. */
496 bfd
= bfd_openr (objname
, NULL
);
498 bfd
= bfd_fdopenr(objname
, NULL
, ldi
->ldinfo_fd
);
500 error("Could not open `%s' as an executable file: %s",
501 objname
, bfd_errmsg(bfd_error
));
504 /* make sure we have an object file */
506 if (bfd_check_format(bfd
, bfd_object
))
507 vp
= map_vmap (bfd
, 0);
509 else if (bfd_check_format(bfd
, bfd_archive
)) {
512 * FIXME??? am I tossing BFDs? bfd?
514 while (last
= bfd_openr_next_archived_file(bfd
, last
))
515 if (STREQ(mem
, last
->filename
))
520 /* FIXME -- should be error */
521 warning("\"%s\": member \"%s\" missing.", bfd
->filename
, mem
);
525 if (!bfd_check_format(last
, bfd_object
)) {
526 bfd_close(last
); /* XXX??? */
530 vp
= map_vmap (last
, bfd
);
535 error ("\"%s\": not in executable format: %s.",
536 objname
, bfd_errmsg(bfd_error
));
539 obj
= allocate_objfile (vp
->bfd
, 0);
542 #ifndef SOLIB_SYMBOLS_MANUAL
543 syms_from_objfile (obj
, 0, 0, 0);
544 new_symfile_objfile (obj
, 0, 0);
545 vmap_symtab (vp
, 0, 0);
552 /* As well as symbol tables, exec_sections need relocation. After
553 the inferior process' termination, there will be a relocated symbol
554 table exist with no corresponding inferior process. At that time, we
555 need to use `exec' bfd, rather than the inferior process's memory space
558 `exec_sections' need to be relocated only once, as long as the exec
559 file remains unchanged.
566 if (execbfd
== exec_bfd
)
571 if (!vmap
|| !exec_ops
.to_sections
)
572 error ("vmap_exec: vmap or exec_ops.to_sections == 0\n");
574 for (i
=0; &exec_ops
.to_sections
[i
] < exec_ops
.to_sections_end
; i
++)
576 if (STREQ(".text", exec_ops
.to_sections
[i
].sec_ptr
->name
))
578 exec_ops
.to_sections
[i
].addr
+= vmap
->tstart
;
579 exec_ops
.to_sections
[i
].endaddr
+= vmap
->tstart
;
581 else if (STREQ(".data", exec_ops
.to_sections
[i
].sec_ptr
->name
))
583 exec_ops
.to_sections
[i
].addr
+= vmap
->dstart
;
584 exec_ops
.to_sections
[i
].endaddr
+= vmap
->dstart
;
590 /* This was for the old, half-assed, core file support. */
592 text_adjustment (abfd
)
596 static int adjustment
;
599 if (exec_bfd
== execbfd
)
602 sect
= bfd_get_section_by_name (abfd
, ".text");
604 adjustment
= sect
->filepos
- sect
->vma
;
606 adjustment
= 0x200; /* just a wild assumption */
613 * vmap_ldinfo - update VMAP info with ldinfo() information
616 * ldi - ^ to ldinfo() results.
619 register struct ld_info
*ldi
;
622 register struct vmap
*vp
;
623 register got_one
, retried
;
627 * for each *ldi, see if we have a corresponding *vp
628 * if so, update the mapping, and symbol table.
629 * if not, add an entry and symbol table.
632 char *name
= ldi
->ldinfo_filename
;
633 char *memb
= name
+ strlen(name
) + 1;
637 if (fstat(ldi
->ldinfo_fd
, &ii
) < 0)
638 fatal("cannot fstat(%d) on %s"
642 for (got_one
= 0, vp
= vmap
; vp
; vp
= vp
->nxt
) {
645 /* First try to find a `vp', which is the same as in ldinfo.
646 If not the same, just continue and grep the next `vp'. If same,
647 relocate its tstart, tend, dstart, dend values. If no such `vp'
648 found, get out of this for loop, add this ldi entry as a new vmap
649 (add_vmap) and come back, fins its `vp' and so on... */
651 /* The filenames are not always sufficient to match on. */
653 if ((name
[0] == '/' && !STREQ(name
, vp
->name
))
654 || (memb
[0] && !STREQ(memb
, vp
->member
)))
657 io
= bfd_cache_lookup(vp
->bfd
); /* totally opaque! */
659 fatal("cannot find BFD's iostream for %s", vp
->name
);
661 /* see if we are referring to the same file */
663 if (fstat(fileno(io
), &vi
) < 0)
664 fatal("cannot fstat BFD for %s", vp
->name
);
666 if (ii
.st_dev
!= vi
.st_dev
|| ii
.st_ino
!= vi
.st_ino
)
670 close(ldi
->ldinfo_fd
);
674 /* found a corresponding VMAP. remap! */
677 vp
->tstart
= ldi
->ldinfo_textorg
;
678 vp
->tend
= vp
->tstart
+ ldi
->ldinfo_textsize
;
679 vp
->dstart
= ldi
->ldinfo_dataorg
;
680 vp
->dend
= vp
->dstart
+ ldi
->ldinfo_datasize
;
683 vp
->tstart
+= vp
->tadj
;
684 vp
->tend
+= vp
->tadj
;
687 /* relocate symbol table(s). */
688 vmap_symtab(vp
, ostart
, &vi
);
690 /* there may be more, so we don't break out of the loop. */
693 /* if there was no matching *vp, we must perforce create the sucker(s) */
694 if (!got_one
&& !retried
) {
699 } while (ldi
->ldinfo_next
700 && (ldi
= (void *) (ldi
->ldinfo_next
+ (char *) ldi
)));
705 * vmap_inferior - print VMAP info for inferior
709 if (inferior_pid
== 0)
710 return 0; /* normal processing */
716 /* Read or write the exec file.
718 Args are address within exec file, address within gdb address-space,
719 length, and a flag indicating whether to read or write.
723 0: We cannot handle this address and length.
724 > 0: We have handled N bytes starting at this address.
725 (If N == length, we did it all.) We might be able
726 to handle more bytes beyond this length, but no
728 < 0: We cannot handle this address, but if somebody
729 else handles (-N) bytes, we can start from there.
731 The same routine is used to handle both core and exec files;
732 we just tail-call it with more arguments to select between them. */
735 xfer_memory (memaddr
, myaddr
, len
, write
, target
)
740 struct target_ops
*target
;
743 struct section_table
*p
;
744 CORE_ADDR nextsectaddr
, memend
;
745 boolean (*xfer_fn
) PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
750 memend
= memaddr
+ len
;
751 xfer_fn
= write
? bfd_set_section_contents
: bfd_get_section_contents
;
752 nextsectaddr
= memend
;
754 for (p
= target
->to_sections
; p
< target
->to_sections_end
; p
++)
756 if (p
->addr
<= memaddr
)
757 if (p
->endaddr
>= memend
)
759 /* Entire transfer is within this section. */
760 res
= xfer_fn (p
->bfd
, p
->sec_ptr
, myaddr
, memaddr
- p
->addr
, len
);
761 return (res
!= false)? len
: 0;
763 else if (p
->endaddr
<= memaddr
)
765 /* This section ends before the transfer starts. */
770 /* This section overlaps the transfer. Just do half. */
771 len
= p
->endaddr
- memaddr
;
772 res
= xfer_fn (p
->bfd
, p
->sec_ptr
, myaddr
, memaddr
- p
->addr
, len
);
773 return (res
!= false)? len
: 0;
775 else if (p
->addr
< nextsectaddr
)
776 nextsectaddr
= p
->addr
;
779 if (nextsectaddr
>= memend
)
780 return 0; /* We can't help */
782 return - (nextsectaddr
- memaddr
); /* Next boundary where we can help */
786 print_section_info (t
, abfd
)
787 struct target_ops
*t
;
790 struct section_table
*p
;
792 printf_filtered ("\t`%s', ", bfd_get_filename(abfd
));
794 printf_filtered ("file type %s.\n", bfd_get_target(abfd
));
796 for (p
= t
->to_sections
; p
< t
->to_sections_end
; p
++) {
797 printf_filtered ("\t%s", local_hex_string_custom (p
->addr
, "08"));
798 printf_filtered (" - %s", local_hex_string_custom (p
->endaddr
, "08"));
800 printf_filtered (" @ %s",
801 local_hex_string_custom (p
->sec_ptr
->filepos
, "08"));
802 printf_filtered (" is %s", bfd_section_name (p
->bfd
, p
->sec_ptr
));
803 if (p
->bfd
!= abfd
) {
804 printf_filtered (" in %s", bfd_get_filename (p
->bfd
));
806 printf_filtered ("\n");
813 struct target_ops
*t
;
815 register struct vmap
*vp
= vmap
;
817 print_section_info (t
, exec_bfd
);
822 printf("\tMapping info for file `%s'.\n", vp
->name
);
824 printf("\t %8.8s %8.8s %8.8s %8.8s %8.8s %s\n",
825 "tstart", "tend", "dstart", "dend", "section", "file(member)");
827 for (; vp
; vp
= vp
->nxt
)
828 printf("\t0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x %s%s%s%s\n",
834 *vp
->member
? "(" : "",
836 *vp
->member
? ")" : "");
840 /* Damon's implementation of set_section_command! It is based on the sex member
841 (which is a section pointer from vmap) of vmap.
842 We will not have multiple vmap entries (one for each section), rather transmit
843 text and data base offsets and fix them at the same time. Elimination of sex
844 entry in vmap make this function obsolute, use the one from exec.c.
845 Need further testing!! FIXMEmgo. */
848 set_section_command(args
, from_tty
)
851 register struct vmap
*vp
= vmap
;
854 unsigned long secaddr
;
859 error("Must specify section name and its virtual address");
861 /* Parse out section name */
862 for (secname
= args
; !isspace(*args
); args
++)
864 seclen
= args
- secname
;
866 /* Parse out new virtual address */
867 secaddr
= parse_and_eval_address(args
);
869 for (vp
= vmap
; vp
; vp
= vp
->nxt
) {
871 , bfd_section_name(vp
->bfd
, vp
->sex
), seclen
)
872 && bfd_section_name(vp
->bfd
, vp
->sex
)[seclen
] == '\0') {
873 offset
= secaddr
- vp
->tstart
;
874 vp
->tstart
+= offset
;
881 if (seclen
>= sizeof(secprint
))
882 seclen
= sizeof(secprint
) - 1;
883 strncpy(secprint
, secname
, seclen
);
884 secprint
[seclen
] = '\0';
885 error("Section %s not found", secprint
);
889 set_section_command (args
, from_tty
)
893 struct section_table
*p
;
896 unsigned long secaddr
;
901 error ("Must specify section name and its virtual address");
903 /* Parse out section name */
904 for (secname
= args
; !isspace(*args
); args
++) ;
905 seclen
= args
- secname
;
907 /* Parse out new virtual address */
908 secaddr
= parse_and_eval_address (args
);
910 for (p
= exec_ops
.to_sections
; p
< exec_ops
.to_sections_end
; p
++) {
911 if (!strncmp (secname
, bfd_section_name (exec_bfd
, p
->sec_ptr
), seclen
)
912 && bfd_section_name (exec_bfd
, p
->sec_ptr
)[seclen
] == '\0') {
913 offset
= secaddr
- p
->addr
;
915 p
->endaddr
+= offset
;
917 exec_files_info(&exec_ops
);
921 if (seclen
>= sizeof (secprint
))
922 seclen
= sizeof (secprint
) - 1;
923 strncpy (secprint
, secname
, seclen
);
924 secprint
[seclen
] = '\0';
925 error ("Section %s not found", secprint
);
930 struct target_ops exec_ops
= {
931 "exec", "Local exec file",
932 "Use an executable file as a target.\n\
933 Specify the filename of the executable file.",
934 exec_file_command
, exec_close
, /* open, close */
935 find_default_attach
, 0, 0, 0, /* attach, detach, resume, wait, */
936 0, 0, /* fetch_registers, store_registers, */
937 0, /* prepare_to_store */
938 xfer_memory
, exec_files_info
,
939 0, 0, /* insert_breakpoint, remove_breakpoint, */
940 0, 0, 0, 0, 0, /* terminal stuff */
941 0, 0, /* kill, load */
943 find_default_create_inferior
,
944 0, /* mourn_inferior */
946 0, /* notice_signals */
947 file_stratum
, 0, /* next */
948 0, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */
949 0, 0, /* section pointers */
950 OPS_MAGIC
, /* Always the last thing */
953 /* Core file stuff. */
955 /* Relocate symtabs and read in shared library info, based on symbols
956 from the core file. */
958 xcoff_relocate_core ()
960 /* Offset of member MEMBER in a struct of type TYPE. */
962 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
965 /* Size of a struct ld_info except for the variable-length filename. */
966 #define LDINFO_SIZE (offsetof (struct ld_info, ldinfo_filename))
970 struct ld_info
*ldip
;
973 /* Allocated size of buffer. */
974 int buffer_size
= LDINFO_SIZE
;
975 char *buffer
= xmalloc (buffer_size
);
976 struct cleanup
*old
= make_cleanup (free_current_contents
, &buffer
);
978 ldinfo_sec
= bfd_get_section_by_name (core_bfd
, ".ldinfo");
979 if (ldinfo_sec
== NULL
)
982 fprintf_filtered (stderr
, "Couldn't get ldinfo from core file: %s\n",
983 bfd_errmsg (bfd_error
));
992 /* Read in everything but the name. */
993 if (bfd_get_section_contents (core_bfd
, ldinfo_sec
, buffer
,
994 offset
, LDINFO_SIZE
) == 0)
1001 if (i
== buffer_size
)
1004 buffer
= xrealloc (buffer
, buffer_size
);
1006 if (bfd_get_section_contents (core_bfd
, ldinfo_sec
, &buffer
[i
],
1007 offset
+ i
, 1) == 0)
1009 if (buffer
[i
++] == '\0')
1011 } while (names_found
< 2);
1013 ldip
= (struct ld_info
*)buffer
;
1015 /* Can't use a file descriptor from the core file; need to open it. */
1016 ldip
->ldinfo_fd
= -1;
1018 /* The first ldinfo is for the exec file, allocated elsewhere. */
1022 vp
= add_vmap (ldip
);
1024 offset
+= ldip
->ldinfo_next
;
1026 vp
->tstart
= ldip
->ldinfo_textorg
;
1027 vp
->tend
= vp
->tstart
+ ldip
->ldinfo_textsize
;
1028 vp
->dstart
= ldip
->ldinfo_dataorg
;
1029 vp
->dend
= vp
->dstart
+ ldip
->ldinfo_datasize
;
1031 if (vp
->tadj
!= 0) {
1032 vp
->tstart
+= vp
->tadj
;
1033 vp
->tend
+= vp
->tadj
;
1036 /* Unless this is the exec file,
1037 add our sections to the section table for the core target. */
1041 struct section_table
*stp
;
1043 count
= core_ops
.to_sections_end
- core_ops
.to_sections
;
1045 core_ops
.to_sections
= (struct section_table
*)
1046 xrealloc (core_ops
.to_sections
,
1047 sizeof (struct section_table
) * count
);
1048 core_ops
.to_sections_end
= core_ops
.to_sections
+ count
;
1049 stp
= core_ops
.to_sections_end
- 2;
1051 /* "Why do we add bfd_section_vma?", I hear you cry.
1052 Well, the start of the section in the file is actually
1053 that far into the section as the struct vmap understands it.
1054 So for text sections, bfd_section_vma tends to be 0x200,
1055 and if vp->tstart is 0xd0002000, then the first byte of
1056 the text section on disk corresponds to address 0xd0002200. */
1058 stp
->sec_ptr
= bfd_get_section_by_name (stp
->bfd
, ".text");
1059 stp
->addr
= bfd_section_vma (stp
->bfd
, stp
->sec_ptr
) + vp
->tstart
;
1060 stp
->endaddr
= bfd_section_vma (stp
->bfd
, stp
->sec_ptr
) + vp
->tend
;
1064 stp
->sec_ptr
= bfd_get_section_by_name (stp
->bfd
, ".data");
1065 stp
->addr
= bfd_section_vma (stp
->bfd
, stp
->sec_ptr
) + vp
->dstart
;
1066 stp
->endaddr
= bfd_section_vma (stp
->bfd
, stp
->sec_ptr
) + vp
->dend
;
1069 vmap_symtab (vp
, 0, 0);
1071 add_text_to_loadinfo (ldip
->ldinfo_textorg
, ldip
->ldinfo_dataorg
);
1072 } while (ldip
->ldinfo_next
!= 0);
1081 add_com("file", class_files
, file_command
,
1082 "Use FILE as program to be debugged.\n\
1083 It is read for its symbols, for getting the contents of pure memory,\n\
1084 and it is the program executed when you use the `run' command.\n\
1085 If FILE cannot be found as specified, your execution directory path\n\
1086 ($PATH) is searched for a command of that name.\n\
1087 No arg means to have no executable file and no symbols.");
1089 add_com("exec-file", class_files
, exec_file_command
,
1090 "Use FILE as program for getting contents of pure memory.\n\
1091 If FILE cannot be found as specified, your execution directory path\n\
1092 is searched for a command of that name.\n\
1093 No arg means have no executable file.");
1095 add_com("section", class_files
, set_section_command
,
1096 "Change the base address of section SECTION of the exec file to ADDR.\n\
1097 This can be used if the exec file does not contain section addresses,\n\
1098 (such as in the a.out format), or when the addresses specified in the\n\
1099 file itself are wrong. Each section must be changed separately. The\n\
1100 ``info files'' command lists all the sections and their addresses.");
1102 add_target(&exec_ops
);