Add explicit #include of "value.h".
[external/binutils.git] / gdb / exec.c
1 /* Work with executable files, for GDB. 
2    Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3    1998, 1999, 2000, 2001
4    Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
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.
12
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.
17
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., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "frame.h"
25 #include "inferior.h"
26 #include "target.h"
27 #include "gdbcmd.h"
28 #include "language.h"
29 #include "symfile.h"
30 #include "objfiles.h"
31 #include "completer.h"
32 #include "value.h"
33
34 #ifdef USG
35 #include <sys/types.h>
36 #endif
37
38 #include <fcntl.h>
39 #include "gdb_string.h"
40
41 #include "gdbcore.h"
42
43 #include <ctype.h>
44 #include "gdb_stat.h"
45 #ifndef O_BINARY
46 #define O_BINARY 0
47 #endif
48
49 #include "xcoffsolib.h"
50
51 struct vmap *map_vmap (bfd *, bfd *);
52
53 void (*file_changed_hook) (char *);
54
55 /* Prototypes for local functions */
56
57 static void add_to_section_table (bfd *, sec_ptr, PTR);
58
59 static void exec_close (int);
60
61 static void file_command (char *, int);
62
63 static void set_section_command (char *, int);
64
65 static void exec_files_info (struct target_ops *);
66
67 static void bfdsec_to_vmap (bfd *, sec_ptr, PTR);
68
69 static int ignore (CORE_ADDR, char *);
70
71 static void init_exec_ops (void);
72
73 void _initialize_exec (void);
74
75 extern int info_verbose;
76
77 /* The target vector for executable files.  */
78
79 struct target_ops exec_ops;
80
81 /* The Binary File Descriptor handle for the executable file.  */
82
83 bfd *exec_bfd = NULL;
84
85 /* Whether to open exec and core files read-only or read-write.  */
86
87 int write_files = 0;
88
89 /* Text start and end addresses (KLUDGE) if needed */
90
91 #ifndef NEED_TEXT_START_END
92 #define NEED_TEXT_START_END (0)
93 #endif
94 CORE_ADDR text_start = 0;
95 CORE_ADDR text_end = 0;
96
97 struct vmap *vmap;
98
99 void
100 exec_open (char *args, int from_tty)
101 {
102   target_preopen (from_tty);
103   exec_file_attach (args, from_tty);
104 }
105
106 /* ARGSUSED */
107 static void
108 exec_close (int quitting)
109 {
110   int need_symtab_cleanup = 0;
111   struct vmap *vp, *nxt;
112
113   for (nxt = vmap; nxt != NULL;)
114     {
115       vp = nxt;
116       nxt = vp->nxt;
117
118       /* if there is an objfile associated with this bfd,
119          free_objfile() will do proper cleanup of objfile *and* bfd. */
120
121       if (vp->objfile)
122         {
123           free_objfile (vp->objfile);
124           need_symtab_cleanup = 1;
125         }
126       else if (vp->bfd != exec_bfd)
127         /* FIXME-leak: We should be freeing vp->name too, I think.  */
128         if (!bfd_close (vp->bfd))
129           warning ("cannot close \"%s\": %s",
130                    vp->name, bfd_errmsg (bfd_get_error ()));
131
132       /* FIXME: This routine is #if 0'd in symfile.c.  What should we
133          be doing here?  Should we just free everything in
134          vp->objfile->symtabs?  Should free_objfile do that?
135          FIXME-as-well: free_objfile already free'd vp->name, so it isn't
136          valid here.  */
137       free_named_symtabs (vp->name);
138       xfree (vp);
139     }
140
141   vmap = NULL;
142
143   if (exec_bfd)
144     {
145       char *name = bfd_get_filename (exec_bfd);
146
147       if (!bfd_close (exec_bfd))
148         warning ("cannot close \"%s\": %s",
149                  name, bfd_errmsg (bfd_get_error ()));
150       xfree (name);
151       exec_bfd = NULL;
152     }
153
154   if (exec_ops.to_sections)
155     {
156       xfree (exec_ops.to_sections);
157       exec_ops.to_sections = NULL;
158       exec_ops.to_sections_end = NULL;
159     }
160 }
161
162 void
163 exec_file_clear (int from_tty)
164 {
165   /* Remove exec file.  */
166   unpush_target (&exec_ops);
167
168   if (from_tty)
169     printf_unfiltered ("No executable file now.\n");
170 }
171
172 /*  Process the first arg in ARGS as the new exec file.
173
174    This function is intended to be behave essentially the same
175    as exec_file_command, except that the latter will detect when
176    a target is being debugged, and will ask the user whether it
177    should be shut down first.  (If the answer is "no", then the
178    new file is ignored.)
179
180    This file is used by exec_file_command, to do the work of opening
181    and processing the exec file after any prompting has happened.
182
183    And, it is used by child_attach, when the attach command was
184    given a pid but not a exec pathname, and the attach command could
185    figure out the pathname from the pid.  (In this case, we shouldn't
186    ask the user whether the current target should be shut down --
187    we're supplying the exec pathname late for good reason.)
188    
189    ARGS is assumed to be the filename. */
190
191 void
192 exec_file_attach (char *filename, int from_tty)
193 {
194   /* Remove any previous exec file.  */
195   unpush_target (&exec_ops);
196
197   /* Now open and digest the file the user requested, if any.  */
198
199   if (!filename)
200     {
201       if (from_tty)
202         printf_unfiltered ("No executable file now.\n");
203     }
204   else
205     {
206       char *scratch_pathname;
207       int scratch_chan;
208
209       scratch_chan = openp (getenv ("PATH"), 1, filename,
210                    write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0,
211                             &scratch_pathname);
212 #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__)
213       if (scratch_chan < 0)
214         {
215           char *exename = alloca (strlen (filename) + 5);
216           strcat (strcpy (exename, filename), ".exe");
217           scratch_chan = openp (getenv ("PATH"), 1, exename, write_files ?
218              O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0, &scratch_pathname);
219         }
220 #endif
221       if (scratch_chan < 0)
222         perror_with_name (filename);
223       exec_bfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan);
224
225       if (!exec_bfd)
226         error ("\"%s\": could not open as an executable file: %s",
227                scratch_pathname, bfd_errmsg (bfd_get_error ()));
228
229       /* At this point, scratch_pathname and exec_bfd->name both point to the
230          same malloc'd string.  However exec_close() will attempt to free it
231          via the exec_bfd->name pointer, so we need to make another copy and
232          leave exec_bfd as the new owner of the original copy. */
233       scratch_pathname = xstrdup (scratch_pathname);
234       make_cleanup (xfree, scratch_pathname);
235
236       if (!bfd_check_format (exec_bfd, bfd_object))
237         {
238           /* Make sure to close exec_bfd, or else "run" might try to use
239              it.  */
240           exec_close (0);
241           error ("\"%s\": not in executable format: %s",
242                  scratch_pathname, bfd_errmsg (bfd_get_error ()));
243         }
244
245       /* FIXME - This should only be run for RS6000, but the ifdef is a poor
246          way to accomplish.  */
247 #ifdef IBM6000_TARGET
248       /* Setup initial vmap. */
249
250       map_vmap (exec_bfd, 0);
251       if (vmap == NULL)
252         {
253           /* Make sure to close exec_bfd, or else "run" might try to use
254              it.  */
255           exec_close (0);
256           error ("\"%s\": can't find the file sections: %s",
257                  scratch_pathname, bfd_errmsg (bfd_get_error ()));
258         }
259 #endif /* IBM6000_TARGET */
260
261       if (build_section_table (exec_bfd, &exec_ops.to_sections,
262                                &exec_ops.to_sections_end))
263         {
264           /* Make sure to close exec_bfd, or else "run" might try to use
265              it.  */
266           exec_close (0);
267           error ("\"%s\": can't find the file sections: %s",
268                  scratch_pathname, bfd_errmsg (bfd_get_error ()));
269         }
270
271       /* text_end is sometimes used for where to put call dummies.  A
272          few ports use these for other purposes too.  */
273       if (NEED_TEXT_START_END)
274         {
275           struct section_table *p;
276
277           /* Set text_start to the lowest address of the start of any
278              readonly code section and set text_end to the highest
279              address of the end of any readonly code section.  */
280           /* FIXME: The comment above does not match the code.  The
281              code checks for sections with are either code *or*
282              readonly.  */
283           text_start = ~(CORE_ADDR) 0;
284           text_end = (CORE_ADDR) 0;
285           for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++)
286             if (bfd_get_section_flags (p->bfd, p->the_bfd_section)
287                 & (SEC_CODE | SEC_READONLY))
288               {
289                 if (text_start > p->addr)
290                   text_start = p->addr;
291                 if (text_end < p->endaddr)
292                   text_end = p->endaddr;
293               }
294         }
295
296       validate_files ();
297
298       set_gdbarch_from_file (exec_bfd);
299
300       push_target (&exec_ops);
301
302       /* Tell display code (if any) about the changed file name.  */
303       if (exec_file_display_hook)
304         (*exec_file_display_hook) (filename);
305     }
306 }
307
308 /*  Process the first arg in ARGS as the new exec file.
309
310    Note that we have to explicitly ignore additional args, since we can
311    be called from file_command(), which also calls symbol_file_command()
312    which can take multiple args.
313    
314    If ARGS is NULL, we just want to close the exec file. */
315
316 static void
317 exec_file_command (char *args, int from_tty)
318 {
319   char **argv;
320   char *filename;
321   
322   target_preopen (from_tty);
323
324   if (args)
325     {
326       /* Scan through the args and pick up the first non option arg
327          as the filename.  */
328
329       argv = buildargv (args);
330       if (argv == NULL)
331         nomem (0);
332
333       make_cleanup_freeargv (argv);
334
335       for (; (*argv != NULL) && (**argv == '-'); argv++)
336         {;
337         }
338       if (*argv == NULL)
339         error ("No executable file name was specified");
340
341       filename = tilde_expand (*argv);
342       make_cleanup (xfree, filename);
343       exec_file_attach (filename, from_tty);
344     }
345   else
346     exec_file_attach (NULL, from_tty);
347 }
348
349 /* Set both the exec file and the symbol file, in one command.  
350    What a novelty.  Why did GDB go through four major releases before this
351    command was added?  */
352
353 static void
354 file_command (char *arg, int from_tty)
355 {
356   /* FIXME, if we lose on reading the symbol file, we should revert
357      the exec file, but that's rough.  */
358   exec_file_command (arg, from_tty);
359   symbol_file_command (arg, from_tty);
360   if (file_changed_hook)
361     file_changed_hook (arg);
362 }
363 \f
364
365 /* Locate all mappable sections of a BFD file. 
366    table_pp_char is a char * to get it through bfd_map_over_sections;
367    we cast it back to its proper type.  */
368
369 static void
370 add_to_section_table (bfd *abfd, sec_ptr asect, PTR table_pp_char)
371 {
372   struct section_table **table_pp = (struct section_table **) table_pp_char;
373   flagword aflag;
374
375   aflag = bfd_get_section_flags (abfd, asect);
376   if (!(aflag & SEC_ALLOC))
377     return;
378   if (0 == bfd_section_size (abfd, asect))
379     return;
380   (*table_pp)->bfd = abfd;
381   (*table_pp)->the_bfd_section = asect;
382   (*table_pp)->addr = bfd_section_vma (abfd, asect);
383   (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect);
384   (*table_pp)++;
385 }
386
387 /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
388    Returns 0 if OK, 1 on error.  */
389
390 int
391 build_section_table (bfd *some_bfd, struct section_table **start,
392                      struct section_table **end)
393 {
394   unsigned count;
395
396   count = bfd_count_sections (some_bfd);
397   if (*start)
398     xfree (* start);
399   *start = (struct section_table *) xmalloc (count * sizeof (**start));
400   *end = *start;
401   bfd_map_over_sections (some_bfd, add_to_section_table, (char *) end);
402   if (*end > *start + count)
403     internal_error (__FILE__, __LINE__, "failed internal consistency check");
404   /* We could realloc the table, but it probably loses for most files.  */
405   return 0;
406 }
407 \f
408 static void
409 bfdsec_to_vmap (bfd *abfd, sec_ptr sect, PTR arg3)
410 {
411   struct vmap_and_bfd *vmap_bfd = (struct vmap_and_bfd *) arg3;
412   struct vmap *vp;
413
414   vp = vmap_bfd->pvmap;
415
416   if ((bfd_get_section_flags (abfd, sect) & SEC_LOAD) == 0)
417     return;
418
419   if (STREQ (bfd_section_name (abfd, sect), ".text"))
420     {
421       vp->tstart = bfd_section_vma (abfd, sect);
422       vp->tend = vp->tstart + bfd_section_size (abfd, sect);
423       vp->tvma = bfd_section_vma (abfd, sect);
424       vp->toffs = sect->filepos;
425     }
426   else if (STREQ (bfd_section_name (abfd, sect), ".data"))
427     {
428       vp->dstart = bfd_section_vma (abfd, sect);
429       vp->dend = vp->dstart + bfd_section_size (abfd, sect);
430       vp->dvma = bfd_section_vma (abfd, sect);
431     }
432   /* Silently ignore other types of sections. (FIXME?)  */
433 }
434
435 /* Make a vmap for ABFD which might be a member of the archive ARCH.
436    Return the new vmap.  */
437
438 struct vmap *
439 map_vmap (bfd *abfd, bfd *arch)
440 {
441   struct vmap_and_bfd vmap_bfd;
442   struct vmap *vp, **vpp;
443
444   vp = (struct vmap *) xmalloc (sizeof (*vp));
445   memset ((char *) vp, '\0', sizeof (*vp));
446   vp->nxt = 0;
447   vp->bfd = abfd;
448   vp->name = bfd_get_filename (arch ? arch : abfd);
449   vp->member = arch ? bfd_get_filename (abfd) : "";
450
451   vmap_bfd.pbfd = arch;
452   vmap_bfd.pvmap = vp;
453   bfd_map_over_sections (abfd, bfdsec_to_vmap, &vmap_bfd);
454
455   /* Find the end of the list and append. */
456   for (vpp = &vmap; *vpp; vpp = &(*vpp)->nxt)
457     ;
458   *vpp = vp;
459
460   return vp;
461 }
462 \f
463 /* Read or write the exec file.
464
465    Args are address within a BFD file, address within gdb address-space,
466    length, and a flag indicating whether to read or write.
467
468    Result is a length:
469
470    0:    We cannot handle this address and length.
471    > 0:  We have handled N bytes starting at this address.
472    (If N == length, we did it all.)  We might be able
473    to handle more bytes beyond this length, but no
474    promises.
475    < 0:  We cannot handle this address, but if somebody
476    else handles (-N) bytes, we can start from there.
477
478    The same routine is used to handle both core and exec files;
479    we just tail-call it with more arguments to select between them.  */
480
481 int
482 xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
483              struct mem_attrib *attrib,
484              struct target_ops *target)
485 {
486   boolean res;
487   struct section_table *p;
488   CORE_ADDR nextsectaddr, memend;
489   boolean (*xfer_fn) (bfd *, sec_ptr, PTR, file_ptr, bfd_size_type);
490   asection *section = NULL;
491
492   if (len <= 0)
493     internal_error (__FILE__, __LINE__, "failed internal consistency check");
494
495   if (overlay_debugging)
496     {
497       section = find_pc_overlay (memaddr);
498       if (pc_in_unmapped_range (memaddr, section))
499         memaddr = overlay_mapped_address (memaddr, section);
500     }
501
502   memend = memaddr + len;
503   xfer_fn = write ? bfd_set_section_contents : bfd_get_section_contents;
504   nextsectaddr = memend;
505
506   for (p = target->to_sections; p < target->to_sections_end; p++)
507     {
508       if (overlay_debugging && section && p->the_bfd_section &&
509           strcmp (section->name, p->the_bfd_section->name) != 0)
510         continue;               /* not the section we need */
511       if (memaddr >= p->addr)
512         if (memend <= p->endaddr)
513           {
514             /* Entire transfer is within this section.  */
515             res = xfer_fn (p->bfd, p->the_bfd_section, myaddr,
516                            memaddr - p->addr, len);
517             return (res != 0) ? len : 0;
518           }
519         else if (memaddr >= p->endaddr)
520           {
521             /* This section ends before the transfer starts.  */
522             continue;
523           }
524         else
525           {
526             /* This section overlaps the transfer.  Just do half.  */
527             len = p->endaddr - memaddr;
528             res = xfer_fn (p->bfd, p->the_bfd_section, myaddr,
529                            memaddr - p->addr, len);
530             return (res != 0) ? len : 0;
531           }
532       else
533         nextsectaddr = min (nextsectaddr, p->addr);
534     }
535
536   if (nextsectaddr >= memend)
537     return 0;                   /* We can't help */
538   else
539     return -(nextsectaddr - memaddr);   /* Next boundary where we can help */
540 }
541 \f
542
543 void
544 print_section_info (struct target_ops *t, bfd *abfd)
545 {
546   struct section_table *p;
547
548   printf_filtered ("\t`%s', ", bfd_get_filename (abfd));
549   wrap_here ("        ");
550   printf_filtered ("file type %s.\n", bfd_get_target (abfd));
551   if (abfd == exec_bfd)
552     {
553       printf_filtered ("\tEntry point: ");
554       print_address_numeric (bfd_get_start_address (abfd), 1, gdb_stdout);
555       printf_filtered ("\n");
556     }
557   for (p = t->to_sections; p < t->to_sections_end; p++)
558     {
559       /* FIXME-32x64 need a print_address_numeric with field width */
560       printf_filtered ("\t%s", local_hex_string_custom ((unsigned long) p->addr, "08l"));
561       printf_filtered (" - %s", local_hex_string_custom ((unsigned long) p->endaddr, "08l"));
562       if (info_verbose)
563         printf_filtered (" @ %s",
564                          local_hex_string_custom ((unsigned long) p->the_bfd_section->filepos, "08l"));
565       printf_filtered (" is %s", bfd_section_name (p->bfd, p->the_bfd_section));
566       if (p->bfd != abfd)
567         {
568           printf_filtered (" in %s", bfd_get_filename (p->bfd));
569         }
570       printf_filtered ("\n");
571     }
572 }
573
574 static void
575 exec_files_info (struct target_ops *t)
576 {
577   print_section_info (t, exec_bfd);
578
579   if (vmap)
580     {
581       struct vmap *vp;
582
583       printf_unfiltered ("\tMapping info for file `%s'.\n", vmap->name);
584       printf_unfiltered ("\t  %*s   %*s   %*s   %*s %8.8s %s\n",
585                          strlen_paddr (), "tstart",
586                          strlen_paddr (), "tend",
587                          strlen_paddr (), "dstart",
588                          strlen_paddr (), "dend",
589                          "section",
590                          "file(member)");
591
592       for (vp = vmap; vp; vp = vp->nxt)
593         printf_unfiltered ("\t0x%s 0x%s 0x%s 0x%s %s%s%s%s\n",
594                            paddr (vp->tstart),
595                            paddr (vp->tend),
596                            paddr (vp->dstart),
597                            paddr (vp->dend),
598                            vp->name,
599                            *vp->member ? "(" : "", vp->member,
600                            *vp->member ? ")" : "");
601     }
602 }
603
604 /* msnyder 5/21/99:
605    exec_set_section_offsets sets the offsets of all the sections
606    in the exec objfile.  */
607
608 void
609 exec_set_section_offsets (bfd_signed_vma text_off, bfd_signed_vma data_off,
610                           bfd_signed_vma bss_off)
611 {
612   struct section_table *sect;
613
614   for (sect = exec_ops.to_sections;
615        sect < exec_ops.to_sections_end;
616        sect++)
617     {
618       flagword flags;
619
620       flags = bfd_get_section_flags (exec_bfd, sect->the_bfd_section);
621
622       if (flags & SEC_CODE)
623         {
624           sect->addr += text_off;
625           sect->endaddr += text_off;
626         }
627       else if (flags & (SEC_DATA | SEC_LOAD))
628         {
629           sect->addr += data_off;
630           sect->endaddr += data_off;
631         }
632       else if (flags & SEC_ALLOC)
633         {
634           sect->addr += bss_off;
635           sect->endaddr += bss_off;
636         }
637     }
638 }
639
640 static void
641 set_section_command (char *args, int from_tty)
642 {
643   struct section_table *p;
644   char *secname;
645   unsigned seclen;
646   unsigned long secaddr;
647   char secprint[100];
648   long offset;
649
650   if (args == 0)
651     error ("Must specify section name and its virtual address");
652
653   /* Parse out section name */
654   for (secname = args; !isspace (*args); args++);
655   seclen = args - secname;
656
657   /* Parse out new virtual address */
658   secaddr = parse_and_eval_address (args);
659
660   for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++)
661     {
662       if (!strncmp (secname, bfd_section_name (exec_bfd, p->the_bfd_section), seclen)
663           && bfd_section_name (exec_bfd, p->the_bfd_section)[seclen] == '\0')
664         {
665           offset = secaddr - p->addr;
666           p->addr += offset;
667           p->endaddr += offset;
668           if (from_tty)
669             exec_files_info (&exec_ops);
670           return;
671         }
672     }
673   if (seclen >= sizeof (secprint))
674     seclen = sizeof (secprint) - 1;
675   strncpy (secprint, secname, seclen);
676   secprint[seclen] = '\0';
677   error ("Section %s not found", secprint);
678 }
679
680 /* If mourn is being called in all the right places, this could be say
681    `gdb internal error' (since generic_mourn calls
682    breakpoint_init_inferior).  */
683
684 static int
685 ignore (CORE_ADDR addr, char *contents)
686 {
687   return 0;
688 }
689
690 /* Fill in the exec file target vector.  Very few entries need to be
691    defined.  */
692
693 void
694 init_exec_ops (void)
695 {
696   exec_ops.to_shortname = "exec";
697   exec_ops.to_longname = "Local exec file";
698   exec_ops.to_doc = "Use an executable file as a target.\n\
699 Specify the filename of the executable file.";
700   exec_ops.to_open = exec_open;
701   exec_ops.to_close = exec_close;
702   exec_ops.to_attach = find_default_attach;
703   exec_ops.to_require_attach = find_default_require_attach;
704   exec_ops.to_require_detach = find_default_require_detach;
705   exec_ops.to_xfer_memory = xfer_memory;
706   exec_ops.to_files_info = exec_files_info;
707   exec_ops.to_insert_breakpoint = ignore;
708   exec_ops.to_remove_breakpoint = ignore;
709   exec_ops.to_create_inferior = find_default_create_inferior;
710   exec_ops.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
711   exec_ops.to_stratum = file_stratum;
712   exec_ops.to_has_memory = 1;
713   exec_ops.to_magic = OPS_MAGIC;
714 }
715
716 void
717 _initialize_exec (void)
718 {
719   struct cmd_list_element *c;
720
721   init_exec_ops ();
722
723   if (!dbx_commands)
724     {
725       c = add_cmd ("file", class_files, file_command,
726                    "Use FILE as program to be debugged.\n\
727 It is read for its symbols, for getting the contents of pure memory,\n\
728 and it is the program executed when you use the `run' command.\n\
729 If FILE cannot be found as specified, your execution directory path\n\
730 ($PATH) is searched for a command of that name.\n\
731 No arg means to have no executable file and no symbols.", &cmdlist);
732       c->completer = filename_completer;
733     }
734
735   c = add_cmd ("exec-file", class_files, exec_file_command,
736                "Use FILE as program for getting contents of pure memory.\n\
737 If FILE cannot be found as specified, your execution directory path\n\
738 is searched for a command of that name.\n\
739 No arg means have no executable file.", &cmdlist);
740   c->completer = filename_completer;
741
742   add_com ("section", class_files, set_section_command,
743            "Change the base address of section SECTION of the exec file to ADDR.\n\
744 This can be used if the exec file does not contain section addresses,\n\
745 (such as in the a.out format), or when the addresses specified in the\n\
746 file itself are wrong.  Each section must be changed separately.  The\n\
747 ``info files'' command lists all the sections and their addresses.");
748
749   add_show_from_set
750     (add_set_cmd ("write", class_support, var_boolean, (char *) &write_files,
751                   "Set writing into executable and core files.",
752                   &setlist),
753      &showlist);
754
755   add_target (&exec_ops);
756 }