s/value_ptr/struct value */
[deliverable/binutils-gdb.git] / gdb / exec.c
CommitLineData
c906108c 1/* Work with executable files, for GDB.
b6ba6518
KB
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001
c5aa993b 4 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b
JM
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. */
c906108c
SS
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"
c5f0f3d0 31#include "completer.h"
fd0407d6 32#include "value.h"
c906108c
SS
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
a14ed312 51struct vmap *map_vmap (bfd *, bfd *);
c906108c 52
507f3c78 53void (*file_changed_hook) (char *);
c906108c
SS
54
55/* Prototypes for local functions */
56
a14ed312 57static void add_to_section_table (bfd *, sec_ptr, PTR);
c906108c 58
a14ed312 59static void exec_close (int);
c906108c 60
a14ed312 61static void file_command (char *, int);
c906108c 62
a14ed312 63static void set_section_command (char *, int);
c906108c 64
a14ed312 65static void exec_files_info (struct target_ops *);
c906108c 66
a14ed312 67static void bfdsec_to_vmap (bfd *, sec_ptr, PTR);
c906108c 68
a14ed312 69static int ignore (CORE_ADDR, char *);
c906108c 70
a14ed312 71static void init_exec_ops (void);
c906108c 72
a14ed312 73void _initialize_exec (void);
c906108c
SS
74
75extern int info_verbose;
76
77/* The target vector for executable files. */
78
79struct target_ops exec_ops;
80
81/* The Binary File Descriptor handle for the executable file. */
82
83bfd *exec_bfd = NULL;
84
85/* Whether to open exec and core files read-only or read-write. */
86
87int 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
94CORE_ADDR text_start = 0;
c5aa993b 95CORE_ADDR text_end = 0;
c906108c
SS
96
97struct vmap *vmap;
98
1adeb98a
FN
99void
100exec_open (char *args, int from_tty)
101{
102 target_preopen (from_tty);
103 exec_file_attach (args, from_tty);
104}
105
c906108c
SS
106/* ARGSUSED */
107static void
fba45db2 108exec_close (int quitting)
c906108c
SS
109{
110 int need_symtab_cleanup = 0;
111 struct vmap *vp, *nxt;
c5aa993b
JM
112
113 for (nxt = vmap; nxt != NULL;)
c906108c
SS
114 {
115 vp = nxt;
116 nxt = vp->nxt;
117
118 /* if there is an objfile associated with this bfd,
c5aa993b
JM
119 free_objfile() will do proper cleanup of objfile *and* bfd. */
120
c906108c
SS
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
c5aa993b
JM
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. */
c906108c 137 free_named_symtabs (vp->name);
b8c9b27d 138 xfree (vp);
c906108c
SS
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 ()));
b8c9b27d 150 xfree (name);
c906108c
SS
151 exec_bfd = NULL;
152 }
153
154 if (exec_ops.to_sections)
155 {
b8c9b27d 156 xfree (exec_ops.to_sections);
c906108c
SS
157 exec_ops.to_sections = NULL;
158 exec_ops.to_sections_end = NULL;
159 }
160}
161
1adeb98a
FN
162void
163exec_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
c906108c
SS
172/* Process the first arg in ARGS as the new exec file.
173
c5aa993b
JM
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.)
c906108c 179
c5aa993b
JM
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.
c906108c 182
c5aa993b
JM
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 --
1adeb98a
FN
187 we're supplying the exec pathname late for good reason.)
188
189 ARGS is assumed to be the filename. */
c906108c
SS
190
191void
1adeb98a 192exec_file_attach (char *filename, int from_tty)
c906108c 193{
c906108c
SS
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
1adeb98a
FN
199 if (!filename)
200 {
201 if (from_tty)
202 printf_unfiltered ("No executable file now.\n");
203 }
204 else
c906108c
SS
205 {
206 char *scratch_pathname;
207 int scratch_chan;
c5aa993b 208
c5aa993b
JM
209 scratch_chan = openp (getenv ("PATH"), 1, filename,
210 write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0,
c906108c 211 &scratch_pathname);
cfc3008e 212#if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__)
c906108c 213 if (scratch_chan < 0)
c5aa993b
JM
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 }
c906108c
SS
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
c5aa993b
JM
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. */
c2d11a7d 233 scratch_pathname = xstrdup (scratch_pathname);
b8c9b27d 234 make_cleanup (xfree, scratch_pathname);
c5aa993b 235
c906108c
SS
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
c5aa993b 246 way to accomplish. */
c906108c
SS
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,
c5aa993b 262 &exec_ops.to_sections_end))
c906108c
SS
263 {
264 /* Make sure to close exec_bfd, or else "run" might try to use
265 it. */
266 exec_close (0);
c5aa993b 267 error ("\"%s\": can't find the file sections: %s",
c906108c
SS
268 scratch_pathname, bfd_errmsg (bfd_get_error ()));
269 }
270
271 /* text_end is sometimes used for where to put call dummies. A
c5aa993b 272 few ports use these for other purposes too. */
c906108c
SS
273 if (NEED_TEXT_START_END)
274 {
275 struct section_table *p;
c5aa993b 276
c906108c
SS
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. */
c5aa993b
JM
283 text_start = ~(CORE_ADDR) 0;
284 text_end = (CORE_ADDR) 0;
c906108c
SS
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 {
c5aa993b 289 if (text_start > p->addr)
c906108c
SS
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 }
c906108c
SS
306}
307
308/* Process the first arg in ARGS as the new exec file.
309
c5aa993b
JM
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()
1adeb98a
FN
312 which can take multiple args.
313
314 If ARGS is NULL, we just want to close the exec file. */
c906108c 315
1adeb98a 316static void
fba45db2 317exec_file_command (char *args, int from_tty)
c906108c 318{
1adeb98a
FN
319 char **argv;
320 char *filename;
321
c906108c 322 target_preopen (from_tty);
1adeb98a
FN
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);
c906108c
SS
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
353static void
fba45db2 354file_command (char *arg, int from_tty)
c906108c
SS
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}
c906108c 363\f
c5aa993b 364
c906108c
SS
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
369static void
fba45db2 370add_to_section_table (bfd *abfd, sec_ptr asect, PTR table_pp_char)
c906108c 371{
c5aa993b 372 struct section_table **table_pp = (struct section_table **) table_pp_char;
c906108c
SS
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
390int
fba45db2
KB
391build_section_table (bfd *some_bfd, struct section_table **start,
392 struct section_table **end)
c906108c
SS
393{
394 unsigned count;
395
396 count = bfd_count_sections (some_bfd);
397 if (*start)
b8c9b27d 398 xfree (* start);
c906108c
SS
399 *start = (struct section_table *) xmalloc (count * sizeof (**start));
400 *end = *start;
c5aa993b 401 bfd_map_over_sections (some_bfd, add_to_section_table, (char *) end);
c906108c 402 if (*end > *start + count)
e1e9e218 403 internal_error (__FILE__, __LINE__, "failed internal consistency check");
c906108c
SS
404 /* We could realloc the table, but it probably loses for most files. */
405 return 0;
406}
407\f
408static void
fba45db2 409bfdsec_to_vmap (bfd *abfd, sec_ptr sect, PTR arg3)
c906108c
SS
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
438struct vmap *
fba45db2 439map_vmap (bfd *abfd, bfd *arch)
c906108c
SS
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) : "";
c5aa993b 450
c906108c
SS
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
c5aa993b
JM
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.
c906108c 477
c5aa993b
JM
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. */
c906108c
SS
480
481int
fba45db2 482xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
29e57380 483 struct mem_attrib *attrib,
fba45db2 484 struct target_ops *target)
c906108c
SS
485{
486 boolean res;
487 struct section_table *p;
488 CORE_ADDR nextsectaddr, memend;
507f3c78 489 boolean (*xfer_fn) (bfd *, sec_ptr, PTR, file_ptr, bfd_size_type);
88665544 490 asection *section = NULL;
c906108c
SS
491
492 if (len <= 0)
e1e9e218 493 internal_error (__FILE__, __LINE__, "failed internal consistency check");
c906108c
SS
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
c906108c
SS
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)
c5aa993b 510 continue; /* not the section we need */
c906108c 511 if (memaddr >= p->addr)
c5aa993b 512 if (memend <= p->endaddr)
c906108c
SS
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 }
c5aa993b 524 else
c906108c
SS
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)
c5aa993b 537 return 0; /* We can't help */
c906108c 538 else
c5aa993b 539 return -(nextsectaddr - memaddr); /* Next boundary where we can help */
c906108c 540}
c906108c 541\f
c5aa993b 542
c906108c 543void
fba45db2 544print_section_info (struct target_ops *t, bfd *abfd)
c906108c
SS
545{
546 struct section_table *p;
547
c5aa993b 548 printf_filtered ("\t`%s', ", bfd_get_filename (abfd));
c906108c 549 wrap_here (" ");
c5aa993b 550 printf_filtered ("file type %s.\n", bfd_get_target (abfd));
c906108c
SS
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
574static void
fba45db2 575exec_files_info (struct target_ops *t)
c906108c
SS
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);
d4f3574e
SS
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",
c5aa993b
JM
590 "file(member)");
591
592 for (vp = vmap; vp; vp = vp->nxt)
d4f3574e
SS
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,
c5aa993b
JM
599 *vp->member ? "(" : "", vp->member,
600 *vp->member ? ")" : "");
c906108c
SS
601 }
602}
603
0f71a2f6
JM
604/* msnyder 5/21/99:
605 exec_set_section_offsets sets the offsets of all the sections
606 in the exec objfile. */
607
608void
fba45db2
KB
609exec_set_section_offsets (bfd_signed_vma text_off, bfd_signed_vma data_off,
610 bfd_signed_vma bss_off)
0f71a2f6
JM
611{
612 struct section_table *sect;
c5aa993b
JM
613
614 for (sect = exec_ops.to_sections;
615 sect < exec_ops.to_sections_end;
0f71a2f6
JM
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 {
c5aa993b 624 sect->addr += text_off;
0f71a2f6
JM
625 sect->endaddr += text_off;
626 }
627 else if (flags & (SEC_DATA | SEC_LOAD))
628 {
c5aa993b 629 sect->addr += data_off;
0f71a2f6
JM
630 sect->endaddr += data_off;
631 }
632 else if (flags & SEC_ALLOC)
633 {
c5aa993b 634 sect->addr += bss_off;
0f71a2f6
JM
635 sect->endaddr += bss_off;
636 }
637 }
638}
639
c906108c 640static void
fba45db2 641set_section_command (char *args, int from_tty)
c906108c
SS
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 */
c5aa993b 654 for (secname = args; !isspace (*args); args++);
c906108c
SS
655 seclen = args - secname;
656
657 /* Parse out new virtual address */
658 secaddr = parse_and_eval_address (args);
659
c5aa993b
JM
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 }
c906108c 672 }
c906108c
SS
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
684static int
fba45db2 685ignore (CORE_ADDR addr, char *contents)
c906108c
SS
686{
687 return 0;
688}
689
690/* Fill in the exec file target vector. Very few entries need to be
691 defined. */
692
693void
fba45db2 694init_exec_ops (void)
c906108c
SS
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\
699Specify the filename of the executable file.";
1adeb98a 700 exec_ops.to_open = exec_open;
c906108c
SS
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;
c5aa993b 713 exec_ops.to_magic = OPS_MAGIC;
c906108c
SS
714}
715
716void
fba45db2 717_initialize_exec (void)
c906108c
SS
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\
727It is read for its symbols, for getting the contents of pure memory,\n\
728and it is the program executed when you use the `run' command.\n\
729If FILE cannot be found as specified, your execution directory path\n\
730($PATH) is searched for a command of that name.\n\
731No 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,
c5aa993b 736 "Use FILE as program for getting contents of pure memory.\n\
c906108c
SS
737If FILE cannot be found as specified, your execution directory path\n\
738is searched for a command of that name.\n\
739No arg means have no executable file.", &cmdlist);
740 c->completer = filename_completer;
741
742 add_com ("section", class_files, set_section_command,
c5aa993b 743 "Change the base address of section SECTION of the exec file to ADDR.\n\
c906108c
SS
744This 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\
746file 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
c5aa993b 750 (add_set_cmd ("write", class_support, var_boolean, (char *) &write_files,
c906108c
SS
751 "Set writing into executable and core files.",
752 &setlist),
753 &showlist);
c5aa993b 754
c906108c
SS
755 add_target (&exec_ops);
756}
This page took 0.14553 seconds and 4 git commands to generate.