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 */
43 #include "xcoffsolib.h"
45 /* Prototypes for local functions */
48 file_command
PARAMS ((char *, int));
51 exec_close
PARAMS ((int));
53 struct section_table
*exec_sections
, *exec_sections_end
;
55 #define eq(s0, s1) !strcmp(s0, s1)
57 /* Whether to open exec and core files read-only or read-write. */
61 extern int info_verbose
;
63 bfd
*exec_bfd
; /* needed by core.c */
65 extern char *getenv();
66 extern void child_create_inferior (), child_attach ();
67 extern void add_syms_addr_command ();
68 extern void symbol_file_command ();
69 static void exec_files_info();
70 extern struct objfile
*lookup_objfile_bfd ();
74 * the vmap struct is used to describe the virtual address space of
75 * the target we are manipulating. The first entry is always the "exec"
76 * file. Subsequent entries correspond to other objects that are
77 * mapped into the address space of a process created from the "exec" file.
78 * These are either in response to exec()ing the file, in which case all
79 * shared libraries are loaded, or a "load" system call, followed by the
80 * user's issuance of a "load" command.
83 struct vmap
*nxt
; /* ^ to next in chain */
84 bfd
*bfd
; /* BFD for mappable object library */
85 char *name
; /* ^ to object file name */
86 char *member
; /* ^ to member name */
87 CORE_ADDR tstart
; /* virtual addr where member is mapped */
88 CORE_ADDR tend
; /* virtual upper bound of member */
89 CORE_ADDR tadj
; /* heuristically derived adjustment */
90 CORE_ADDR dstart
; /* virtual address of data start */
91 CORE_ADDR dend
; /* vitrual address of data end */
100 static struct vmap
*vmap
; /* current vmap */
103 struct vmap
*vmap
; /* current vmap */
105 extern struct target_ops exec_ops
;
108 /* exec_close - done with exec file, clean up all resources. */
113 register struct vmap
*vp
, *nxt
;
116 for (nxt
= vmap
; vp
= nxt
; )
120 /* if there is an objfile associated with this bfd,
121 free_objfile() will do proper cleanup of objfile *and* bfd. */
123 if (obj
= lookup_objfile_bfd (vp
->bfd
))
128 free_named_symtabs(vp
->name
);
135 bfd_close (exec_bfd
);
138 if (exec_ops
.to_sections
) {
139 free (exec_ops
.to_sections
);
140 exec_ops
.to_sections
= NULL
;
141 exec_ops
.to_sections_end
= NULL
;
146 * exec_file_command - handle the "exec" command, &c.
149 exec_file_command(filename
, from_tty
)
152 target_preopen(from_tty
);
154 /* Remove any previous exec file. */
155 unpush_target(&exec_ops
);
157 /* Now open and digest the file the user requested, if any. */
160 char *scratch_pathname
;
163 filename
= tilde_expand(filename
);
164 make_cleanup (free
, filename
);
166 scratch_chan
= openp(getenv("PATH"), 1, filename
,
167 write_files
? O_RDWR
: O_RDONLY
, 0,
169 if (scratch_chan
< 0)
170 perror_with_name(filename
);
172 exec_bfd
= bfd_fdopenr(scratch_pathname
, NULL
, scratch_chan
);
174 error("Could not open `%s' as an executable file: %s"
175 , scratch_pathname
, bfd_errmsg(bfd_error
));
177 /* make sure we have an object file */
179 if (!bfd_check_format(exec_bfd
, bfd_object
))
180 error("\"%s\": not in executable format: %s.",
181 scratch_pathname
, bfd_errmsg(bfd_error
));
184 /* setup initial vmap */
186 map_vmap (exec_bfd
, 0);
188 error("Can't find the file sections in `%s': %s",
189 exec_bfd
->filename
, bfd_errmsg(bfd_error
));
191 if (build_section_table (exec_bfd
, &exec_ops
.to_sections
,
192 &exec_ops
.to_sections_end
))
193 error ("Can't find the file sections in `%s': %s",
194 exec_bfd
->filename
, bfd_errmsg (bfd_error
));
196 /* make sure core, if present, matches */
199 push_target(&exec_ops
);
201 /* Tell display code(if any) about the changed file name. */
203 if (exec_file_display_hook
)
204 (*exec_file_display_hook
)(filename
);
207 exec_close(0); /* just in case */
209 printf("No exec file now.\n");
213 /* Set both the exec file and the symbol file, in one command. What a
214 * novelty. Why did GDB go through four major releases before this
218 file_command(arg
, from_tty
)
221 exec_file_command(arg
, from_tty
);
222 symbol_file_command(arg
, from_tty
);
225 /* Locate all mappable sections of a BFD file.
226 table_pp_char is a char * to get it through bfd_map_over_sections;
227 we cast it back to its proper type. */
230 add_to_section_table (abfd
, asect
, table_pp_char
)
235 struct section_table
**table_pp
= (struct section_table
**)table_pp_char
;
238 aflag
= bfd_get_section_flags (abfd
, asect
);
239 /* FIXME, we need to handle BSS segment here...it alloc's but doesn't load */
240 if (!(aflag
& SEC_LOAD
))
242 if (0 == bfd_section_size (abfd
, asect
))
244 (*table_pp
)->bfd
= abfd
;
245 (*table_pp
)->sec_ptr
= asect
;
246 (*table_pp
)->addr
= bfd_section_vma (abfd
, asect
);
247 (*table_pp
)->endaddr
= (*table_pp
)->addr
+ bfd_section_size (abfd
, asect
);
252 build_section_table (some_bfd
, start
, end
)
254 struct section_table
**start
, **end
;
258 count
= bfd_count_sections (some_bfd
);
260 abort(); /* return 1? */
263 *start
= (struct section_table
*) xmalloc (count
* sizeof (**start
));
265 bfd_map_over_sections (some_bfd
, add_to_section_table
, (char *)end
);
266 if (*end
> *start
+ count
)
268 /* We could realloc the table, but it probably loses for most files. */
273 * lookup_symtab_bfd - find if we currently have any symbol tables from bfd
276 lookup_objfile_bfd(bfd
*bfd
) {
277 register struct objfile
*s
;
279 for (s
= object_files
; s
; s
= s
->next
)
287 sex_to_vmap(bfd
*bf
, sec_ptr sex
, struct vmap_and_bfd
*vmap_bfd
)
289 register struct vmap
*vp
, **vpp
;
290 register struct symtab
*syms
;
291 bfd
*arch
= vmap_bfd
->pbfd
;
292 vp
= vmap_bfd
->pvmap
;
294 if ((bfd_get_section_flags(bf
, sex
) & SEC_LOAD
) == 0)
297 if (!strcmp(bfd_section_name(bf
, sex
), ".text")) {
299 vp
->tend
= vp
->tstart
+ bfd_section_size(bf
, sex
);
301 /* When it comes to this adjustment value, in contrast to our previous
302 belief shared objects should behave the same as the main load segment.
303 This is the offset from the beginning of text section to the first
306 vp
->tadj
= sex
->filepos
- bfd_section_vma(bf
, sex
);
309 else if (!strcmp(bfd_section_name(bf
, sex
), ".data")) {
311 vp
->dend
= vp
->dstart
+ bfd_section_size(bf
, sex
);
314 else if (!strcmp(bfd_section_name(bf
, sex
), ".bss")) /* FIXMEmgo */
315 printf ("bss section in exec! Don't know what the heck to do!\n");
318 /* Make a vmap for the BFD "bf", which might be a member of the archive
319 BFD "arch". If we have not yet read in symbols for this file, do so. */
321 map_vmap (bfd
*bf
, bfd
*arch
)
323 struct vmap_and_bfd vmap_bfd
;
324 struct vmap
*vp
, **vpp
;
327 vp
= (void*) xmalloc (sizeof (*vp
));
328 bzero (vp
, sizeof (*vp
));
331 vp
->name
= bfd_get_filename(arch
? arch
: bf
);
332 vp
->member
= arch
? bfd_get_filename(bf
) : "";
334 vmap_bfd
.pbfd
= arch
;
336 bfd_map_over_sections (bf
, sex_to_vmap
, &vmap_bfd
);
338 obj
= lookup_objfile_bfd (bf
);
339 if (exec_bfd
&& !obj
) {
340 obj
= allocate_objfile (bf
, 0);
343 This is only needed
if we want to load shared libraries no matter what
.
344 Since we provide the choice of incremental loading of shared objects now
,
345 we don
't have to load them as default anymore.
347 syms_from_objfile (obj, 0, 0, 0);
348 new_symfile_objfile (obj, 0, 0);
352 /* find the end of the list, and append. */
353 for (vpp = &vmap; *vpp; vpp = &(*vpp)->nxt)
359 /* true, if symbol table and minimal symbol table are relocated. */
361 int symtab_relocated = 0;
364 /* vmap_symtab - handle symbol translation on vmapping */
366 vmap_symtab(vp, old_start, vip)
367 register struct vmap *vp;
371 register struct symtab *s;
372 register struct objfile *objfile;
373 register struct minimal_symbol *msymbol;
376 * for each symbol table generated from the vp->bfd
378 ALL_OBJFILES (objfile)
380 for (s = objfile -> symtabs; s != NULL; s = s -> next) {
382 /* skip over if this is not relocatable and doesn't have a line table */
383 if (s
->nonreloc
&& !LINETABLE (s
))
386 /* matching the symbol table's BFD and the *vp's BFD is hairy.
387 exec_file creates a seperate BFD for possibly the
388 same file as symbol_file.FIXME ALL THIS MUST BE RECTIFIED. */
390 if (objfile
->obfd
== vp
->bfd
) {
391 /* if they match, we luck out. */
393 } else if (vp
->member
[0]) {
394 /* no match, and member present, not this one. */
401 * no match, and no member. need to be sure.
403 io
= bfd_cache_lookup(objfile
->obfd
);
405 fatal("cannot find BFD's iostream for sym");
407 * see if we are referring to the same file
409 if (fstat(fileno(io
), &si
) < 0)
410 fatal("cannot fstat BFD for sym");
412 if (vip
&& (si
.st_dev
!= vip
->st_dev
413 || si
.st_ino
!= vip
->st_ino
))
417 if (vp
->tstart
!= old_start
) {
419 /* Once we find a relocation base address for one of the symtabs
420 in this objfile, it will be the same for all symtabs in this
421 objfile. Clean this algorithm. FIXME. */
423 for (; s
; s
= s
->next
)
424 if (!s
->nonreloc
|| LINETABLE(s
))
425 vmap_symtab_1(s
, vp
, old_start
);
428 Himm
.., recently we nullified trampoline entry names in order
not
429 to confuse them with real symbols
. Appearently
this turned into a
430 problem
, and msymbol vector did
not get relocated properly
. If
431 msymbols have to have non
-null names
, then we should name
432 trampoline entries with empty strings
.
434 ALL_MSYMBOLS (objfile
, msymbol
)
436 for (msymbol
= objfile
->msymbols
;
437 msymbol
->name
|| msymbol
->address
; (msymbol
)++)
439 if (msymbol
->address
< TEXT_SEGMENT_BASE
)
440 msymbol
-> address
+= vp
->tstart
- old_start
;
447 if (vp
->tstart
!= old_start
) {
450 We don
't have a valid `objfile' at
this point
. This is moved into the
451 previous statement
; ALL_OBJFILES() for-loop
.
453 ALL_MSYMBOLS (objfile
, msymbol
)
454 if (msymbol
->address
< TEXT_SEGMENT_BASE
)
455 msymbol
-> address
+= vp
->tstart
- old_start
;
458 /* breakpoints need to be relocated as well. */
459 fixup_breakpoints (0, TEXT_SEGMENT_BASE
, vp
->tstart
- old_start
);
462 symtab_relocated
= 1;
466 vmap_symtab_1(s
, vp
, old_start
)
467 register struct symtab
*s
;
468 register struct vmap
*vp
;
473 register struct linetable
*l
;
474 struct blockvector
*bv
;
475 register struct block
*b
;
477 register ulong reloc
, dreloc
;
479 if ((reloc
= vp
->tstart
- old_start
) == 0)
482 dreloc
= vp
->dstart
; /* data relocation */
485 * The line table must be relocated. This is only present for
486 * .text sections, so only vp->text type maps need be considered.
491 for (i
= 0; i
< len
; i
++)
492 l
->item
[i
].pc
+= reloc
;
495 /* if this symbol table is not relocatable, only line table should
496 be relocated and the rest ignored. */
501 len
= BLOCKVECTOR_NBLOCKS(bv
);
503 for (i
= 0; i
< len
; i
++) {
504 b
= BLOCKVECTOR_BLOCK(bv
, i
);
506 BLOCK_START(b
) += reloc
;
507 BLOCK_END(b
) += reloc
;
509 blen
= BLOCK_NSYMS(b
);
510 for (j
= 0; j
< blen
; j
++) {
511 register struct symbol
*sym
;
513 sym
= BLOCK_SYM(b
, j
);
514 switch (SYMBOL_NAMESPACE(sym
)) {
515 case STRUCT_NAMESPACE
:
516 case UNDEF_NAMESPACE
:
519 case LABEL_NAMESPACE
:
524 switch (SYMBOL_CLASS(sym
)) {
526 case LOC_CONST_BYTES
:
540 SYMBOL_VALUE_ADDRESS(sym
) += reloc
;
544 SYMBOL_VALUE_ADDRESS(sym
) += dreloc
;
551 fatal("botched symbol class %x"
552 , SYMBOL_CLASS(sym
));
560 * add_vmap - add a new vmap entry based on ldinfo() information
563 register struct ld_info
*ldi
; {
565 register char *mem
, *objname
;
567 /* This ldi structure was allocated using alloca() in
568 aixcoff_relocate_symtab(). Now we need to have persistent object
569 and member names, so we should save them. */
571 mem
= ldi
->ldinfo_filename
+ strlen(ldi
->ldinfo_filename
) + 1;
572 mem
= savestring (mem
, strlen (mem
));
573 objname
= savestring (ldi
->ldinfo_filename
, strlen (ldi
->ldinfo_filename
));
575 bfd
= bfd_fdopenr(objname
, NULL
, ldi
->ldinfo_fd
);
577 error("Could not open `%s' as an executable file: %s",
578 objname
, bfd_errmsg(bfd_error
));
581 /* make sure we have an object file */
583 if (bfd_check_format(bfd
, bfd_object
))
586 else if (bfd_check_format(bfd
, bfd_archive
)) {
589 * FIXME??? am I tossing BFDs? bfd?
591 while (last
= bfd_openr_next_archived_file(bfd
, last
))
592 if (eq(mem
, last
->filename
))
597 /* FIXME -- should be error */
598 warning("\"%s\": member \"%s\" missing.", bfd
->filename
, mem
);
602 if (!bfd_check_format(last
, bfd_object
)) {
603 bfd_close(last
); /* XXX??? */
607 map_vmap (last
, bfd
);
612 /* FIXME -- should be error */
613 warning("\"%s\": not in executable format: %s."
614 , objname
, bfd_errmsg(bfd_error
));
620 /* As well as symbol tables, exec_sections need relocation. After
621 the inferior process' termination, there will be a relocated symbol
622 table exist with no corresponding inferior process. At that time, we
623 need to use `exec' bfd, rather than the inferior process's memory space
626 `exec_sections' need to be relocated only once, as long as the exec
627 file remains unchanged.
632 if (execbfd
== exec_bfd
)
637 /* First exec section is `.text', second is `.data'. If this is changed,
638 then this routine will choke. */
640 if (!vmap
|| !exec_ops
.to_sections
||
641 strcmp (exec_ops
.to_sections
[0].sec_ptr
->name
, ".text") ||
642 strcmp (exec_ops
.to_sections
[1].sec_ptr
->name
, ".data"))
644 fatal ("aix: Improper exec_ops sections.");
646 exec_ops
.to_sections
[0].addr
+= vmap
->tstart
;
647 exec_ops
.to_sections
[0].endaddr
+= vmap
->tstart
;
648 exec_ops
.to_sections
[1].addr
+= vmap
->dstart
;
649 exec_ops
.to_sections
[1].endaddr
+= vmap
->dstart
;
654 text_adjustment (abfd
)
658 static int adjustment
;
661 if (exec_bfd
== execbfd
)
664 sect
= bfd_get_section_by_name (abfd
, ".text");
666 adjustment
= sect
->filepos
- sect
->vma
;
668 adjustment
= 0x200; /* just a wild assumption */
675 * vmap_ldinfo - update VMAP info with ldinfo() information
678 * ldi - ^ to ldinfo() results.
681 register struct ld_info
*ldi
;
684 register struct vmap
*vp
;
685 register got_one
, retried
;
689 * for each *ldi, see if we have a corresponding *vp
690 * if so, update the mapping, and symbol table.
691 * if not, add an entry and symbol table.
694 char *name
= ldi
->ldinfo_filename
;
695 char *memb
= name
+ strlen(name
) + 1;
699 if (fstat(ldi
->ldinfo_fd
, &ii
) < 0)
700 fatal("cannot fstat(%d) on %s"
704 for (got_one
= 0, vp
= vmap
; vp
; vp
= vp
->nxt
) {
707 /* First try to find a `vp', which is the same as in ldinfo.
708 If not the same, just continue and grep the next `vp'. If same,
709 relocate its tstart, tend, dstart, dend values. If no such `vp'
710 found, get out of this for loop, add this ldi entry as a new vmap
711 (add_vmap) and come back, fins its `vp' and so on... */
713 /* The filenames are not always sufficient to match on. */
715 if ((name
[0] == "/" && !eq(name
, vp
->name
))
716 || (memb
[0] && !eq(memb
, vp
->member
)))
719 io
= bfd_cache_lookup(vp
->bfd
); /* totally opaque! */
721 fatal("cannot find BFD's iostream for %s", vp
->name
);
723 /* see if we are referring to the same file */
725 if (fstat(fileno(io
), &vi
) < 0)
726 fatal("cannot fstat BFD for %s", vp
->name
);
728 if (ii
.st_dev
!= vi
.st_dev
|| ii
.st_ino
!= vi
.st_ino
)
732 close(ldi
->ldinfo_fd
);
736 /* found a corresponding VMAP. remap! */
739 vp
->tstart
= ldi
->ldinfo_textorg
;
740 vp
->tend
= vp
->tstart
+ ldi
->ldinfo_textsize
;
741 vp
->dstart
= ldi
->ldinfo_dataorg
;
742 vp
->dend
= vp
->dstart
+ ldi
->ldinfo_datasize
;
745 vp
->tstart
+= vp
->tadj
;
746 vp
->tend
+= vp
->tadj
;
749 /* relocate symbol table(s). */
750 vmap_symtab(vp
, ostart
, &vi
);
752 /* there may be more, so we don't break out of the loop. */
755 /* if there was no matching *vp, we must perforce create the sucker(s) */
756 if (!got_one
&& !retried
) {
761 } while (ldi
->ldinfo_next
762 && (ldi
= (void *) (ldi
->ldinfo_next
+ (char *) ldi
)));
767 * vmap_inferior - print VMAP info for inferior
771 if (inferior_pid
== 0)
772 return 0; /* normal processing */
778 /* Read or write the exec file.
780 Args are address within exec file, address within gdb address-space,
781 length, and a flag indicating whether to read or write.
785 0: We cannot handle this address and length.
786 > 0: We have handled N bytes starting at this address.
787 (If N == length, we did it all.) We might be able
788 to handle more bytes beyond this length, but no
790 < 0: We cannot handle this address, but if somebody
791 else handles (-N) bytes, we can start from there.
793 The same routine is used to handle both core and exec files;
794 we just tail-call it with more arguments to select between them. */
797 xfer_memory (memaddr
, myaddr
, len
, write
, target
)
802 struct target_ops
*target
;
805 struct section_table
*p
;
806 CORE_ADDR nextsectaddr
, memend
;
807 boolean (*xfer_fn
) PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
812 memend
= memaddr
+ len
;
813 xfer_fn
= write
? bfd_set_section_contents
: bfd_get_section_contents
;
814 nextsectaddr
= memend
;
816 for (p
= target
->to_sections
; p
< target
->to_sections_end
; p
++)
818 if (p
->addr
<= memaddr
)
819 if (p
->endaddr
>= memend
)
821 /* Entire transfer is within this section. */
822 res
= xfer_fn (p
->bfd
, p
->sec_ptr
, myaddr
, memaddr
- p
->addr
, len
);
823 return (res
!= false)? len
: 0;
825 else if (p
->endaddr
<= memaddr
)
827 /* This section ends before the transfer starts. */
832 /* This section overlaps the transfer. Just do half. */
833 len
= p
->endaddr
- memaddr
;
834 res
= xfer_fn (p
->bfd
, p
->sec_ptr
, myaddr
, memaddr
- p
->addr
, len
);
835 return (res
!= false)? len
: 0;
837 else if (p
->addr
< nextsectaddr
)
838 nextsectaddr
= p
->addr
;
841 if (nextsectaddr
>= memend
)
842 return 0; /* We can't help */
844 return - (nextsectaddr
- memaddr
); /* Next boundary where we can help */
848 print_section_info (t
, abfd
)
849 struct target_ops
*t
;
852 struct section_table
*p
;
854 printf_filtered ("\t`%s', ", bfd_get_filename(abfd
));
856 printf_filtered ("file type %s.\n", bfd_get_target(abfd
));
858 for (p
= t
->to_sections
; p
< t
->to_sections_end
; p
++) {
859 printf_filtered ("\t%s", local_hex_string_custom (p
->addr
, "08"));
860 printf_filtered (" - %s", local_hex_string_custom (p
->endaddr
, "08"));
862 printf_filtered (" @ %s",
863 local_hex_string_custom (p
->sec_ptr
->filepos
, "08"));
864 printf_filtered (" is %s", bfd_section_name (p
->bfd
, p
->sec_ptr
));
865 if (p
->bfd
!= abfd
) {
866 printf_filtered (" in %s", bfd_get_filename (p
->bfd
));
868 printf_filtered ("\n");
875 struct target_ops
*t
;
877 register struct vmap
*vp
= vmap
;
879 print_section_info (t
, exec_bfd
);
884 printf("\tMapping info for file `%s'.\n", vp
->name
);
886 printf("\t %8.8s %8.8s %8.8s %8.8s %8.8s %s\n",
887 "tstart", "tend", "dstart", "dend", "section", "file(member)");
889 for (; vp
; vp
= vp
->nxt
)
890 printf("\t0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x %s%s%s%s\n",
896 *vp
->member
? "(" : "",
898 *vp
->member
? ")" : "");
902 /* Damon's implementation of set_section_command! It is based on the sex member
903 (which is a section pointer from vmap) of vmap.
904 We will not have multiple vmap entries (one for each section), rather transmit
905 text and data base offsets and fix them at the same time. Elimination of sex
906 entry in vmap make this function obsolute, use the one from exec.c.
907 Need further testing!! FIXMEmgo. */
910 set_section_command(args
, from_tty
)
913 register struct vmap
*vp
= vmap
;
916 unsigned long secaddr
;
921 error("Must specify section name and its virtual address");
923 /* Parse out section name */
924 for (secname
= args
; !isspace(*args
); args
++)
926 seclen
= args
- secname
;
928 /* Parse out new virtual address */
929 secaddr
= parse_and_eval_address(args
);
931 for (vp
= vmap
; vp
; vp
= vp
->nxt
) {
933 , bfd_section_name(vp
->bfd
, vp
->sex
), seclen
)
934 && bfd_section_name(vp
->bfd
, vp
->sex
)[seclen
] == '\0') {
935 offset
= secaddr
- vp
->tstart
;
936 vp
->tstart
+= offset
;
943 if (seclen
>= sizeof(secprint
))
944 seclen
= sizeof(secprint
) - 1;
945 strncpy(secprint
, secname
, seclen
);
946 secprint
[seclen
] = '\0';
947 error("Section %s not found", secprint
);
951 set_section_command (args
, from_tty
)
955 struct section_table
*p
;
958 unsigned long secaddr
;
963 error ("Must specify section name and its virtual address");
965 /* Parse out section name */
966 for (secname
= args
; !isspace(*args
); args
++) ;
967 seclen
= args
- secname
;
969 /* Parse out new virtual address */
970 secaddr
= parse_and_eval_address (args
);
972 for (p
= exec_ops
.to_sections
; p
< exec_ops
.to_sections_end
; p
++) {
973 if (!strncmp (secname
, bfd_section_name (exec_bfd
, p
->sec_ptr
), seclen
)
974 && bfd_section_name (exec_bfd
, p
->sec_ptr
)[seclen
] == '\0') {
975 offset
= secaddr
- p
->addr
;
977 p
->endaddr
+= offset
;
979 exec_files_info(&exec_ops
);
983 if (seclen
>= sizeof (secprint
))
984 seclen
= sizeof (secprint
) - 1;
985 strncpy (secprint
, secname
, seclen
);
986 secprint
[seclen
] = '\0';
987 error ("Section %s not found", secprint
);
992 struct target_ops exec_ops
= {
993 "exec", "Local exec file",
994 "Use an executable file as a target.\n\
995 Specify the filename of the executable file.",
996 exec_file_command
, exec_close
, /* open, close */
997 child_attach
, 0, 0, 0, /* attach, detach, resume, wait, */
998 0, 0, /* fetch_registers, store_registers, */
999 0, 0, 0, /* prepare_to_store, conv_to, conv_from, */
1000 xfer_memory
, exec_files_info
,
1001 0, 0, /* insert_breakpoint, remove_breakpoint, */
1002 0, 0, 0, 0, 0, /* terminal stuff */
1003 0, 0, /* kill, load */
1005 child_create_inferior
,
1006 0, /* mourn_inferior */
1007 file_stratum
, 0, /* next */
1008 0, 1, 0, 0, 0, /* all mem, mem, stack, regs, exec */
1009 0, 0, /* section pointers */
1010 OPS_MAGIC
, /* Always the last thing */
1018 add_com("file", class_files
, file_command
,
1019 "Use FILE as program to be debugged.\n\
1020 It is read for its symbols, for getting the contents of pure memory,\n\
1021 and it is the program executed when you use the `run' command.\n\
1022 If FILE cannot be found as specified, your execution directory path\n\
1023 ($PATH) is searched for a command of that name.\n\
1024 No arg means to have no executable file and no symbols.");
1026 add_com("exec-file", class_files
, exec_file_command
,
1027 "Use FILE as program for getting contents of pure memory.\n\
1028 If FILE cannot be found as specified, your execution directory path\n\
1029 is searched for a command of that name.\n\
1030 No arg means have no executable file.");
1032 add_com("section", class_files
, set_section_command
,
1033 "Change the base address of section SECTION of the exec file to ADDR.\n\
1034 This can be used if the exec file does not contain section addresses,\n\
1035 (such as in the a.out format), or when the addresses specified in the\n\
1036 file itself are wrong. Each section must be changed separately. The\n\
1037 ``info files'' command lists all the sections and their addresses.");
1039 add_target(&exec_ops
);