]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Work with executable files, for GDB. |
b83ed019 | 2 | Copyright 1988, 1989, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
bdbd5f50 | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
bdbd5f50 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
bdbd5f50 | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
bdbd5f50 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 | 19 | |
bd5635a1 | 20 | #include "defs.h" |
bd5635a1 RP |
21 | #include "frame.h" |
22 | #include "inferior.h" | |
23 | #include "target.h" | |
bdbd5f50 | 24 | #include "gdbcmd.h" |
b02fd8ca | 25 | #include "language.h" |
806f810b SS |
26 | #include "symfile.h" |
27 | #include "objfiles.h" | |
bd5635a1 RP |
28 | |
29 | #ifdef USG | |
30 | #include <sys/types.h> | |
31 | #endif | |
32 | ||
33 | #include <sys/param.h> | |
34 | #include <fcntl.h> | |
2b576293 | 35 | #include "gdb_string.h" |
bd5635a1 RP |
36 | |
37 | #include "gdbcore.h" | |
38 | ||
f2ebc25f | 39 | #include <ctype.h> |
2b576293 | 40 | #include "gdb_stat.h" |
a8e033f2 SG |
41 | #ifndef O_BINARY |
42 | #define O_BINARY 0 | |
43 | #endif | |
bd5635a1 | 44 | |
806f810b SS |
45 | #include "xcoffsolib.h" |
46 | ||
47 | struct vmap *map_vmap PARAMS ((bfd *, bfd *)); | |
48 | ||
be772100 JG |
49 | /* Prototypes for local functions */ |
50 | ||
806f810b | 51 | static void add_to_section_table PARAMS ((bfd *, sec_ptr, PTR)); |
be772100 | 52 | |
806f810b | 53 | static void exec_close PARAMS ((int)); |
be772100 | 54 | |
806f810b | 55 | static void file_command PARAMS ((char *, int)); |
be772100 | 56 | |
806f810b | 57 | static void set_section_command PARAMS ((char *, int)); |
be772100 | 58 | |
806f810b | 59 | static void exec_files_info PARAMS ((struct target_ops *)); |
be772100 JG |
60 | |
61 | extern int info_verbose; | |
bd5635a1 RP |
62 | |
63 | /* The Binary File Descriptor handle for the executable file. */ | |
64 | ||
65 | bfd *exec_bfd = NULL; | |
66 | ||
bdbd5f50 | 67 | /* Whether to open exec and core files read-only or read-write. */ |
bd5635a1 | 68 | |
bdbd5f50 | 69 | int write_files = 0; |
bd5635a1 | 70 | |
7730bd5a JG |
71 | /* Text start and end addresses (KLUDGE) if needed */ |
72 | ||
dad0e12d | 73 | #ifdef NEED_TEXT_START_END |
7730bd5a JG |
74 | CORE_ADDR text_start = 0; |
75 | CORE_ADDR text_end = 0; | |
76 | #endif | |
77 | ||
806f810b SS |
78 | struct vmap *vmap; |
79 | ||
bd5635a1 RP |
80 | /* Forward decl */ |
81 | ||
82 | extern struct target_ops exec_ops; | |
83 | ||
bdbd5f50 | 84 | /* ARGSUSED */ |
be772100 | 85 | static void |
bd5635a1 RP |
86 | exec_close (quitting) |
87 | int quitting; | |
88 | { | |
806f810b SS |
89 | int need_symtab_cleanup = 0; |
90 | struct vmap *vp, *nxt; | |
91 | ||
92 | for (nxt = vmap; nxt != NULL; ) | |
93 | { | |
94 | vp = nxt; | |
95 | nxt = vp->nxt; | |
96 | ||
97 | /* if there is an objfile associated with this bfd, | |
98 | free_objfile() will do proper cleanup of objfile *and* bfd. */ | |
99 | ||
100 | if (vp->objfile) | |
101 | { | |
102 | free_objfile (vp->objfile); | |
103 | need_symtab_cleanup = 1; | |
104 | } | |
105 | else if (vp->bfd != exec_bfd) | |
e7b5942b JK |
106 | /* FIXME-leak: We should be freeing vp->name too, I think. */ |
107 | if (!bfd_close (vp->bfd)) | |
108 | warning ("cannot close \"%s\": %s", | |
109 | vp->name, bfd_errmsg (bfd_get_error ())); | |
806f810b SS |
110 | |
111 | /* FIXME: This routine is #if 0'd in symfile.c. What should we | |
112 | be doing here? Should we just free everything in | |
e7b5942b JK |
113 | vp->objfile->symtabs? Should free_objfile do that? |
114 | FIXME-as-well: free_objfile already free'd vp->name, so it isn't | |
115 | valid here. */ | |
806f810b SS |
116 | free_named_symtabs (vp->name); |
117 | free (vp); | |
118 | } | |
e7b5942b | 119 | |
806f810b SS |
120 | vmap = NULL; |
121 | ||
122 | if (exec_bfd) | |
123 | { | |
124 | char *name = bfd_get_filename (exec_bfd); | |
125 | ||
e7b5942b JK |
126 | if (!bfd_close (exec_bfd)) |
127 | warning ("cannot close \"%s\": %s", | |
128 | name, bfd_errmsg (bfd_get_error ())); | |
806f810b SS |
129 | free (name); |
130 | exec_bfd = NULL; | |
131 | } | |
132 | ||
133 | if (exec_ops.to_sections) | |
134 | { | |
135 | free ((PTR)exec_ops.to_sections); | |
136 | exec_ops.to_sections = NULL; | |
137 | exec_ops.to_sections_end = NULL; | |
138 | } | |
bd5635a1 RP |
139 | } |
140 | ||
be772100 JG |
141 | /* Process the first arg in ARGS as the new exec file. |
142 | ||
143 | Note that we have to explicitly ignore additional args, since we can | |
144 | be called from file_command(), which also calls symbol_file_command() | |
145 | which can take multiple args. */ | |
146 | ||
bd5635a1 | 147 | void |
be772100 JG |
148 | exec_file_command (args, from_tty) |
149 | char *args; | |
bd5635a1 RP |
150 | int from_tty; |
151 | { | |
be772100 JG |
152 | char **argv; |
153 | char *filename; | |
154 | ||
f2fc6e7a | 155 | target_preopen (from_tty); |
bd5635a1 RP |
156 | |
157 | /* Remove any previous exec file. */ | |
158 | unpush_target (&exec_ops); | |
159 | ||
160 | /* Now open and digest the file the user requested, if any. */ | |
161 | ||
be772100 | 162 | if (args) |
bd5635a1 RP |
163 | { |
164 | char *scratch_pathname; | |
165 | int scratch_chan; | |
166 | ||
be772100 | 167 | /* Scan through the args and pick up the first non option arg |
806f810b SS |
168 | as the filename. */ |
169 | ||
170 | argv = buildargv (args); | |
171 | if (argv == NULL) | |
172 | nomem (0); | |
be772100 | 173 | |
be772100 JG |
174 | make_cleanup (freeargv, (char *) argv); |
175 | ||
176 | for (; (*argv != NULL) && (**argv == '-'); argv++) {;} | |
177 | if (*argv == NULL) | |
806f810b | 178 | error ("no exec file name was specified"); |
be772100 JG |
179 | |
180 | filename = tilde_expand (*argv); | |
bd5635a1 RP |
181 | make_cleanup (free, filename); |
182 | ||
bdbd5f50 | 183 | scratch_chan = openp (getenv ("PATH"), 1, filename, |
a8e033f2 | 184 | write_files? O_RDWR|O_BINARY: O_RDONLY|O_BINARY, 0, |
bd5635a1 RP |
185 | &scratch_pathname); |
186 | if (scratch_chan < 0) | |
187 | perror_with_name (filename); | |
188 | ||
b1eaba9a | 189 | exec_bfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan); |
bd5635a1 | 190 | if (!exec_bfd) |
806f810b | 191 | error ("\"%s\": could not open as an executable file: %s", |
c4a081e1 | 192 | scratch_pathname, bfd_errmsg (bfd_get_error ())); |
bd5635a1 | 193 | if (!bfd_check_format (exec_bfd, bfd_object)) |
b02fd8ca JK |
194 | { |
195 | /* Make sure to close exec_bfd, or else "run" might try to use | |
196 | it. */ | |
197 | exec_close (0); | |
806f810b SS |
198 | error ("\"%s\": not in executable format: %s", |
199 | scratch_pathname, bfd_errmsg (bfd_get_error ())); | |
200 | } | |
201 | ||
202 | /* FIXME - This should only be run for RS6000, but the ifdef is a poor | |
203 | way to accomplish. */ | |
204 | #ifdef IBM6000_TARGET | |
205 | /* Setup initial vmap. */ | |
206 | ||
207 | map_vmap (exec_bfd, 0); | |
208 | if (vmap == NULL) | |
209 | { | |
210 | /* Make sure to close exec_bfd, or else "run" might try to use | |
211 | it. */ | |
212 | exec_close (0); | |
213 | error ("\"%s\": can't find the file sections: %s", | |
c4a081e1 | 214 | scratch_pathname, bfd_errmsg (bfd_get_error ())); |
b02fd8ca | 215 | } |
806f810b | 216 | #endif /* IBM6000_TARGET */ |
bd5635a1 | 217 | |
be772100 JG |
218 | if (build_section_table (exec_bfd, &exec_ops.to_sections, |
219 | &exec_ops.to_sections_end)) | |
b02fd8ca JK |
220 | { |
221 | /* Make sure to close exec_bfd, or else "run" might try to use | |
222 | it. */ | |
223 | exec_close (0); | |
806f810b SS |
224 | error ("\"%s\": can't find the file sections: %s", |
225 | scratch_pathname, bfd_errmsg (bfd_get_error ())); | |
b02fd8ca | 226 | } |
bd5635a1 | 227 | |
dad0e12d | 228 | #ifdef NEED_TEXT_START_END |
b02fd8ca JK |
229 | |
230 | /* text_end is sometimes used for where to put call dummies. A | |
231 | few ports use these for other purposes too. */ | |
232 | ||
7730bd5a JG |
233 | { |
234 | struct section_table *p; | |
b02fd8ca JK |
235 | |
236 | /* Set text_start to the lowest address of the start of any | |
237 | readonly code section and set text_end to the highest | |
238 | address of the end of any readonly code section. */ | |
e7b5942b JK |
239 | /* FIXME: The comment above does not match the code. The code |
240 | checks for sections with are either code *or* readonly. */ | |
b02fd8ca JK |
241 | |
242 | text_start = ~(CORE_ADDR)0; | |
243 | text_end = (CORE_ADDR)0; | |
be772100 | 244 | for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++) |
b83ed019 | 245 | if (bfd_get_section_flags (p->bfd, p->the_bfd_section) |
b02fd8ca | 246 | & (SEC_CODE | SEC_READONLY)) |
dad0e12d | 247 | { |
b02fd8ca JK |
248 | if (text_start > p->addr) |
249 | text_start = p->addr; | |
250 | if (text_end < p->endaddr) | |
251 | text_end = p->endaddr; | |
dad0e12d | 252 | } |
7730bd5a JG |
253 | } |
254 | #endif | |
255 | ||
bd5635a1 RP |
256 | validate_files (); |
257 | ||
b83ed019 ILT |
258 | set_endian_from_file (exec_bfd); |
259 | ||
bd5635a1 RP |
260 | push_target (&exec_ops); |
261 | ||
262 | /* Tell display code (if any) about the changed file name. */ | |
263 | if (exec_file_display_hook) | |
264 | (*exec_file_display_hook) (filename); | |
265 | } | |
266 | else if (from_tty) | |
b02fd8ca | 267 | printf_unfiltered ("No exec file now.\n"); |
bd5635a1 RP |
268 | } |
269 | ||
270 | /* Set both the exec file and the symbol file, in one command. | |
271 | What a novelty. Why did GDB go through four major releases before this | |
272 | command was added? */ | |
273 | ||
be772100 | 274 | static void |
bd5635a1 RP |
275 | file_command (arg, from_tty) |
276 | char *arg; | |
277 | int from_tty; | |
278 | { | |
279 | /* FIXME, if we lose on reading the symbol file, we should revert | |
280 | the exec file, but that's rough. */ | |
281 | exec_file_command (arg, from_tty); | |
282 | symbol_file_command (arg, from_tty); | |
283 | } | |
284 | ||
285 | \f | |
bdbd5f50 JG |
286 | /* Locate all mappable sections of a BFD file. |
287 | table_pp_char is a char * to get it through bfd_map_over_sections; | |
288 | we cast it back to its proper type. */ | |
bd5635a1 | 289 | |
be772100 | 290 | static void |
bdbd5f50 | 291 | add_to_section_table (abfd, asect, table_pp_char) |
bd5635a1 RP |
292 | bfd *abfd; |
293 | sec_ptr asect; | |
be772100 | 294 | PTR table_pp_char; |
bd5635a1 | 295 | { |
bdbd5f50 | 296 | struct section_table **table_pp = (struct section_table **)table_pp_char; |
bd5635a1 RP |
297 | flagword aflag; |
298 | ||
299 | aflag = bfd_get_section_flags (abfd, asect); | |
c4a081e1 | 300 | if (!(aflag & SEC_ALLOC)) |
bd5635a1 | 301 | return; |
dad0e12d JG |
302 | if (0 == bfd_section_size (abfd, asect)) |
303 | return; | |
bdbd5f50 | 304 | (*table_pp)->bfd = abfd; |
b83ed019 | 305 | (*table_pp)->the_bfd_section = asect; |
bd5635a1 RP |
306 | (*table_pp)->addr = bfd_section_vma (abfd, asect); |
307 | (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect); | |
308 | (*table_pp)++; | |
309 | } | |
310 | ||
be772100 JG |
311 | /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR. |
312 | Returns 0 if OK, 1 on error. */ | |
313 | ||
bd5635a1 RP |
314 | int |
315 | build_section_table (some_bfd, start, end) | |
316 | bfd *some_bfd; | |
317 | struct section_table **start, **end; | |
318 | { | |
319 | unsigned count; | |
320 | ||
321 | count = bfd_count_sections (some_bfd); | |
777bef06 | 322 | if (*start) |
be772100 | 323 | free ((PTR)*start); |
bd5635a1 RP |
324 | *start = (struct section_table *) xmalloc (count * sizeof (**start)); |
325 | *end = *start; | |
bdbd5f50 | 326 | bfd_map_over_sections (some_bfd, add_to_section_table, (char *)end); |
bd5635a1 RP |
327 | if (*end > *start + count) |
328 | abort(); | |
329 | /* We could realloc the table, but it probably loses for most files. */ | |
330 | return 0; | |
331 | } | |
332 | \f | |
806f810b SS |
333 | static void |
334 | bfdsec_to_vmap(abfd, sect, arg3) | |
335 | bfd *abfd; | |
336 | sec_ptr sect; | |
337 | PTR arg3; | |
338 | { | |
339 | struct vmap_and_bfd *vmap_bfd = (struct vmap_and_bfd *) arg3; | |
340 | struct vmap *vp; | |
341 | ||
342 | vp = vmap_bfd->pvmap; | |
343 | ||
344 | if ((bfd_get_section_flags (abfd, sect) & SEC_LOAD) == 0) | |
345 | return; | |
346 | ||
347 | if (STREQ (bfd_section_name (abfd, sect), ".text")) | |
348 | { | |
349 | vp->tstart = 0; | |
350 | vp->tend = vp->tstart + bfd_section_size (abfd, sect); | |
351 | ||
352 | /* When it comes to this adjustment value, in contrast to our previous | |
353 | belief shared objects should behave the same as the main load segment. | |
354 | This is the offset from the beginning of text section to the first | |
355 | real instruction. */ | |
356 | ||
357 | vp->tadj = sect->filepos - bfd_section_vma (abfd, sect); | |
358 | } | |
359 | else if (STREQ (bfd_section_name (abfd, sect), ".data")) | |
360 | { | |
361 | vp->dstart = 0; | |
362 | vp->dend = vp->dstart + bfd_section_size (abfd, sect); | |
363 | } | |
364 | /* Silently ignore other types of sections. (FIXME?) */ | |
365 | } | |
366 | ||
367 | /* Make a vmap for ABFD which might be a member of the archive ARCH. | |
368 | Return the new vmap. */ | |
369 | ||
370 | struct vmap * | |
371 | map_vmap (abfd, arch) | |
372 | bfd *abfd; | |
373 | bfd *arch; | |
374 | { | |
375 | struct vmap_and_bfd vmap_bfd; | |
376 | struct vmap *vp, **vpp; | |
377 | ||
e7b5942b | 378 | vp = (struct vmap *) xmalloc (sizeof (*vp)); |
806f810b SS |
379 | memset ((char *) vp, '\0', sizeof (*vp)); |
380 | vp->nxt = 0; | |
381 | vp->bfd = abfd; | |
382 | vp->name = bfd_get_filename (arch ? arch : abfd); | |
383 | vp->member = arch ? bfd_get_filename (abfd) : ""; | |
384 | ||
385 | vmap_bfd.pbfd = arch; | |
386 | vmap_bfd.pvmap = vp; | |
387 | bfd_map_over_sections (abfd, bfdsec_to_vmap, &vmap_bfd); | |
388 | ||
389 | /* Find the end of the list and append. */ | |
390 | for (vpp = &vmap; *vpp; vpp = &(*vpp)->nxt) | |
391 | ; | |
392 | *vpp = vp; | |
393 | ||
394 | return vp; | |
395 | } | |
396 | \f | |
bd5635a1 RP |
397 | /* Read or write the exec file. |
398 | ||
bdbd5f50 | 399 | Args are address within a BFD file, address within gdb address-space, |
bd5635a1 RP |
400 | length, and a flag indicating whether to read or write. |
401 | ||
402 | Result is a length: | |
403 | ||
404 | 0: We cannot handle this address and length. | |
405 | > 0: We have handled N bytes starting at this address. | |
406 | (If N == length, we did it all.) We might be able | |
407 | to handle more bytes beyond this length, but no | |
408 | promises. | |
409 | < 0: We cannot handle this address, but if somebody | |
410 | else handles (-N) bytes, we can start from there. | |
411 | ||
412 | The same routine is used to handle both core and exec files; | |
413 | we just tail-call it with more arguments to select between them. */ | |
414 | ||
415 | int | |
bdbd5f50 | 416 | xfer_memory (memaddr, myaddr, len, write, target) |
bd5635a1 RP |
417 | CORE_ADDR memaddr; |
418 | char *myaddr; | |
419 | int len; | |
420 | int write; | |
bdbd5f50 | 421 | struct target_ops *target; |
bd5635a1 RP |
422 | { |
423 | boolean res; | |
424 | struct section_table *p; | |
425 | CORE_ADDR nextsectaddr, memend; | |
be772100 | 426 | boolean (*xfer_fn) PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type)); |
bd5635a1 RP |
427 | |
428 | if (len <= 0) | |
429 | abort(); | |
430 | ||
431 | memend = memaddr + len; | |
806f810b | 432 | xfer_fn = write ? bfd_set_section_contents : bfd_get_section_contents; |
bd5635a1 RP |
433 | nextsectaddr = memend; |
434 | ||
be772100 | 435 | for (p = target->to_sections; p < target->to_sections_end; p++) |
bd5635a1 RP |
436 | { |
437 | if (p->addr <= memaddr) | |
438 | if (p->endaddr >= memend) | |
439 | { | |
440 | /* Entire transfer is within this section. */ | |
806f810b SS |
441 | res = xfer_fn (p->bfd, p->the_bfd_section, myaddr, |
442 | memaddr - p->addr, len); | |
b83ed019 | 443 | return (res != 0) ? len : 0; |
bd5635a1 RP |
444 | } |
445 | else if (p->endaddr <= memaddr) | |
446 | { | |
447 | /* This section ends before the transfer starts. */ | |
448 | continue; | |
449 | } | |
450 | else | |
451 | { | |
452 | /* This section overlaps the transfer. Just do half. */ | |
453 | len = p->endaddr - memaddr; | |
806f810b SS |
454 | res = xfer_fn (p->bfd, p->the_bfd_section, myaddr, |
455 | memaddr - p->addr, len); | |
b83ed019 | 456 | return (res != 0) ? len : 0; |
bd5635a1 RP |
457 | } |
458 | else if (p->addr < nextsectaddr) | |
459 | nextsectaddr = p->addr; | |
460 | } | |
461 | ||
462 | if (nextsectaddr >= memend) | |
463 | return 0; /* We can't help */ | |
464 | else | |
465 | return - (nextsectaddr - memaddr); /* Next boundary where we can help */ | |
466 | } | |
467 | ||
bd5635a1 RP |
468 | #ifdef FIXME |
469 | #ifdef REG_STACK_SEGMENT | |
470 | /* MOVE TO BFD... */ | |
471 | /* Pyramids and AM29000s have an extra segment in the virtual address space | |
472 | for the (control) stack of register-window frames. The AM29000 folk | |
473 | call it the "register stack" rather than the "memory stack". */ | |
474 | else if (memaddr >= reg_stack_start && memaddr < reg_stack_end) | |
475 | { | |
476 | i = min (len, reg_stack_end - memaddr); | |
477 | fileptr = memaddr - reg_stack_start + reg_stack_offset; | |
478 | wanna_xfer = coredata; | |
479 | } | |
480 | #endif /* REG_STACK_SEGMENT */ | |
117f631e | 481 | #endif /* FIXME */ |
bd5635a1 | 482 | \f |
be772100 JG |
483 | void |
484 | print_section_info (t, abfd) | |
485 | struct target_ops *t; | |
486 | bfd *abfd; | |
bd5635a1 RP |
487 | { |
488 | struct section_table *p; | |
489 | ||
be772100 | 490 | printf_filtered ("\t`%s', ", bfd_get_filename(abfd)); |
7d9884b9 | 491 | wrap_here (" "); |
be772100 | 492 | printf_filtered ("file type %s.\n", bfd_get_target(abfd)); |
b83ed019 ILT |
493 | if (abfd == exec_bfd) |
494 | { | |
495 | printf_filtered ("\tEntry point: "); | |
496 | print_address_numeric (bfd_get_start_address (abfd), 1, gdb_stdout); | |
497 | printf_filtered ("\n"); | |
498 | } | |
c4a081e1 DM |
499 | for (p = t->to_sections; p < t->to_sections_end; p++) |
500 | { | |
501 | /* FIXME-32x64 need a print_address_numeric with field width */ | |
502 | printf_filtered ("\t%s", local_hex_string_custom ((unsigned long) p->addr, "08l")); | |
503 | printf_filtered (" - %s", local_hex_string_custom ((unsigned long) p->endaddr, "08l")); | |
504 | if (info_verbose) | |
505 | printf_filtered (" @ %s", | |
b83ed019 ILT |
506 | local_hex_string_custom ((unsigned long) p->the_bfd_section->filepos, "08l")); |
507 | printf_filtered (" is %s", bfd_section_name (p->bfd, p->the_bfd_section)); | |
c4a081e1 DM |
508 | if (p->bfd != abfd) |
509 | { | |
510 | printf_filtered (" in %s", bfd_get_filename (p->bfd)); | |
511 | } | |
512 | printf_filtered ("\n"); | |
be772100 | 513 | } |
bd5635a1 RP |
514 | } |
515 | ||
be772100 JG |
516 | static void |
517 | exec_files_info (t) | |
806f810b | 518 | struct target_ops *t; |
be772100 JG |
519 | { |
520 | print_section_info (t, exec_bfd); | |
806f810b SS |
521 | |
522 | if (vmap) | |
523 | { | |
524 | struct vmap *vp; | |
525 | ||
526 | printf_unfiltered ("\tMapping info for file `%s'.\n", vmap->name); | |
527 | printf_unfiltered ("\t %8.8s %8.8s %8.8s %8.8s %8.8s %s\n", | |
528 | "tstart", "tend", "dstart", "dend", "section", | |
529 | "file(member)"); | |
530 | ||
531 | for (vp = vmap; vp; vp = vp->nxt) | |
532 | printf_unfiltered ("\t0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x %s%s%s%s\n", | |
533 | vp->tstart, vp->tend, vp->dstart, vp->dend, vp->name, | |
534 | *vp->member ? "(" : "", vp->member, | |
535 | *vp->member ? ")" : ""); | |
536 | } | |
be772100 JG |
537 | } |
538 | ||
f2fc6e7a JK |
539 | static void |
540 | set_section_command (args, from_tty) | |
541 | char *args; | |
542 | int from_tty; | |
543 | { | |
544 | struct section_table *p; | |
545 | char *secname; | |
546 | unsigned seclen; | |
547 | unsigned long secaddr; | |
548 | char secprint[100]; | |
549 | long offset; | |
550 | ||
551 | if (args == 0) | |
552 | error ("Must specify section name and its virtual address"); | |
553 | ||
554 | /* Parse out section name */ | |
555 | for (secname = args; !isspace(*args); args++) ; | |
556 | seclen = args - secname; | |
557 | ||
558 | /* Parse out new virtual address */ | |
559 | secaddr = parse_and_eval_address (args); | |
560 | ||
be772100 | 561 | for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++) { |
b83ed019 ILT |
562 | if (!strncmp (secname, bfd_section_name (exec_bfd, p->the_bfd_section), seclen) |
563 | && bfd_section_name (exec_bfd, p->the_bfd_section)[seclen] == '\0') { | |
f2fc6e7a JK |
564 | offset = secaddr - p->addr; |
565 | p->addr += offset; | |
566 | p->endaddr += offset; | |
be772100 JG |
567 | if (from_tty) |
568 | exec_files_info(&exec_ops); | |
f2fc6e7a JK |
569 | return; |
570 | } | |
571 | } | |
572 | if (seclen >= sizeof (secprint)) | |
573 | seclen = sizeof (secprint) - 1; | |
574 | strncpy (secprint, secname, seclen); | |
575 | secprint[seclen] = '\0'; | |
576 | error ("Section %s not found", secprint); | |
577 | } | |
578 | ||
b1eaba9a | 579 | /* If mourn is being called in all the right places, this could be say |
b02fd8ca | 580 | `gdb internal error' (since generic_mourn calls breakpoint_init_inferior). */ |
b1eaba9a SG |
581 | |
582 | static int | |
583 | ignore (addr, contents) | |
584 | CORE_ADDR addr; | |
585 | char *contents; | |
586 | { | |
587 | return 0; | |
588 | } | |
589 | ||
bd5635a1 | 590 | struct target_ops exec_ops = { |
2b576293 C |
591 | "exec", /* to_shortname */ |
592 | "Local exec file", /* to_longname */ | |
593 | "Use an executable file as a target.\n\ | |
594 | Specify the filename of the executable file.", /* to_doc */ | |
595 | exec_file_command, /* to_open */ | |
596 | exec_close, /* to_close */ | |
597 | find_default_attach, /* to_attach */ | |
598 | 0, /* to_detach */ | |
599 | 0, /* to_resume */ | |
600 | 0, /* to_wait */ | |
601 | 0, /* to_fetch_registers */ | |
602 | 0, /* to_store_registers */ | |
603 | 0, /* to_prepare_to_store */ | |
604 | xfer_memory, /* to_xfer_memory */ | |
605 | exec_files_info, /* to_files_info */ | |
606 | ignore, /* to_insert_breakpoint */ | |
607 | ignore, /* to_remove_breakpoint */ | |
608 | 0, /* to_terminal_init */ | |
609 | 0, /* to_terminal_inferior */ | |
610 | 0, /* to_terminal_ours_for_output */ | |
611 | 0, /* to_terminal_ours */ | |
612 | 0, /* to_terminal_info */ | |
613 | 0, /* to_kill */ | |
614 | 0, /* to_load */ | |
615 | 0, /* to_lookup_symbol */ | |
616 | find_default_create_inferior, /* to_create_inferior */ | |
617 | 0, /* to_mourn_inferior */ | |
618 | 0, /* to_can_run */ | |
619 | 0, /* to_notice_signals */ | |
620 | 0, /* to_thread_alive */ | |
621 | 0, /* to_stop */ | |
622 | file_stratum, /* to_stratum */ | |
623 | 0, /* to_next */ | |
624 | 0, /* to_has_all_memory */ | |
625 | 1, /* to_has_memory */ | |
626 | 0, /* to_has_stack */ | |
627 | 0, /* to_has_registers */ | |
628 | 0, /* to_has_execution */ | |
629 | 0, /* to_sections */ | |
630 | 0, /* to_sections_end */ | |
631 | OPS_MAGIC, /* to_magic */ | |
bd5635a1 RP |
632 | }; |
633 | ||
634 | void | |
635 | _initialize_exec() | |
636 | { | |
b1eaba9a | 637 | struct cmd_list_element *c; |
bd5635a1 | 638 | |
b1eaba9a SG |
639 | c = add_cmd ("file", class_files, file_command, |
640 | "Use FILE as program to be debugged.\n\ | |
bd5635a1 RP |
641 | It is read for its symbols, for getting the contents of pure memory,\n\ |
642 | and it is the program executed when you use the `run' command.\n\ | |
643 | If FILE cannot be found as specified, your execution directory path\n\ | |
644 | ($PATH) is searched for a command of that name.\n\ | |
b1eaba9a SG |
645 | No arg means to have no executable file and no symbols.", &cmdlist); |
646 | c->completer = filename_completer; | |
bd5635a1 | 647 | |
b1eaba9a | 648 | c = add_cmd ("exec-file", class_files, exec_file_command, |
bd5635a1 RP |
649 | "Use FILE as program for getting contents of pure memory.\n\ |
650 | If FILE cannot be found as specified, your execution directory path\n\ | |
651 | is searched for a command of that name.\n\ | |
b1eaba9a SG |
652 | No arg means have no executable file.", &cmdlist); |
653 | c->completer = filename_completer; | |
bd5635a1 | 654 | |
f2fc6e7a JK |
655 | add_com ("section", class_files, set_section_command, |
656 | "Change the base address of section SECTION of the exec file to ADDR.\n\ | |
657 | This can be used if the exec file does not contain section addresses,\n\ | |
658 | (such as in the a.out format), or when the addresses specified in the\n\ | |
659 | file itself are wrong. Each section must be changed separately. The\n\ | |
660 | ``info files'' command lists all the sections and their addresses."); | |
661 | ||
bdbd5f50 JG |
662 | add_show_from_set |
663 | (add_set_cmd ("write", class_support, var_boolean, (char *)&write_files, | |
664 | "Set writing into executable and core files.", | |
665 | &setlist), | |
666 | &showlist); | |
667 | ||
bd5635a1 RP |
668 | add_target (&exec_ops); |
669 | } |