26 #include "filenames.h"
40 #include "readline/readline.h"
143 char *exec_file, *full_exec_path = NULL;
147 if (exec_file != NULL)
152 if (exec_file == NULL)
157 if (*
gdb_sysroot !=
'\0' && IS_ABSOLUTE_PATH (exec_file))
160 if (full_exec_path == NULL)
170 full_exec_path = xstrdup (exec_file);
219 int load_via_target = 0;
220 char *scratch_pathname, *canonical_pathname;
237 warning (
_(
"writing into executable files is "
238 "not supported for %s sysroots"),
241 scratch_pathname = xstrdup (filename);
246 canonical_pathname = scratch_pathname;
251 filename, write_files ?
254 #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__)
255 if (scratch_chan < 0)
257 char *exename = alloca (strlen (filename) + 5);
259 strcat (strcpy (exename, filename),
".exe");
261 exename, write_files ?
267 if (scratch_chan < 0)
278 if (write_files && !load_via_target)
280 FOPEN_RUB, scratch_chan);
286 error (
_(
"\"%s\": could not open as an executable file: %s"),
287 scratch_pathname, bfd_errmsg (bfd_get_error ()));
298 if (!bfd_check_format_matches (
exec_bfd, bfd_object, &matching))
303 error (
_(
"\"%s\": not in executable format: %s"),
313 error (
_(
"\"%s\": can't find the file sections: %s"),
314 scratch_pathname, bfd_errmsg (bfd_get_error ()));
331 (*deprecated_exec_file_display_hook) (filename);
336 bfd_cache_close_all ();
355 && !
query (
_(
"A program is being debugged already.\n"
356 "Are you sure you want to change the file? ")))
357 error (
_(
"File not changed."));
369 for (; (*argv != NULL) && (**argv ==
'-'); argv++)
373 error (
_(
"No executable file name was specified"));
375 filename = tilde_expand (*argv);
419 aflag = bfd_get_section_flags (abfd, asect);
420 if (!(aflag & SEC_ALLOC))
423 (*table_pp)->owner = NULL;
424 (*table_pp)->the_bfd_section = asect;
425 (*table_pp)->addr = bfd_section_vma (abfd, asect);
426 (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect);
452 new_count = adjustment + old_count;
475 count = bfd_count_sections (some_bfd);
481 if (*end > *start + count)
483 _(
"failed internal consistency check"));
506 for (i = 0; i < count; ++i)
508 table->
sections[space + i] = sections[i];
553 gdb_assert (ts < table->sections + space + count);
558 ts->
owner = (
void *) objfile;
577 if (src->
owner != owner)
594 if (old_count + (dest - src) == 0)
623 for (s =
exec_bfd->sections; s; s = s->next)
625 if ((s->flags & SEC_LOAD) == 0
626 || (s->flags & SEC_READONLY) == 0)
630 size = bfd_get_section_size (s);
631 if (vma <= offset && offset < (vma + size))
635 amt = (vma +
size) - offset;
639 amt = bfd_get_section_contents (
exec_bfd, s,
640 readbuf, offset - vma, amt);
670 for (p = sections; p < sections_end; p++)
674 & SEC_READONLY) == 0)
710 available_memory = section_table_available_memory (available_memory,
734 if (offset >= r->
start)
759 const char *section_name)
768 _(
"failed internal consistency check"));
770 for (p = sections; p < sections_end; p++)
773 bfd *abfd = asect->owner;
775 if (section_name && strcmp (section_name, asect->name) != 0)
777 if (memaddr >= p->
addr)
779 if (memend <= p->endaddr)
783 res = bfd_set_section_contents (abfd, asect,
784 writebuf, memaddr - p->
addr,
787 res = bfd_get_section_contents (abfd, asect,
788 readbuf, memaddr - p->
addr,
799 else if (memaddr >= p->
endaddr)
809 res = bfd_set_section_contents (abfd, asect,
810 writebuf, memaddr - p->
addr,
813 res = bfd_get_section_contents (abfd, asect,
814 readbuf, memaddr - p->
addr,
838 const char *annex,
gdb_byte *readbuf,
846 offset, len, xfered_len,
870 bfd_vma displacement = 0;
873 for (p = t->
sections; p < t->sections_end; p++)
876 bfd *pbfd = psect->owner;
878 if ((bfd_get_section_flags (pbfd, psect) & (SEC_ALLOC | SEC_LOAD))
879 != (SEC_ALLOC | SEC_LOAD))
882 if (bfd_get_section_vma (pbfd, psect) <= abfd->start_address
883 && abfd->start_address < (bfd_get_section_vma (pbfd, psect)
884 + bfd_get_section_size (psect)))
886 displacement = p->
addr - bfd_get_section_vma (pbfd, psect);
891 warning (
_(
"Cannot find section for the entry point of %s."),
892 bfd_get_filename (abfd));
895 bfd_get_start_address (abfd)
900 for (p = t->
sections; p < t->sections_end; p++)
903 bfd *pbfd = psect->owner;
939 unsigned long secaddr;
945 error (
_(
"Must specify section name and its virtual address"));
948 for (secname = args; !isspace (*args); args++);
949 seclen = args - secname;
957 if (!strncmp (secname, bfd_section_name (p->bfd,
961 offset = secaddr - p->
addr;
969 if (seclen >=
sizeof (secprint))
970 seclen =
sizeof (secprint) - 1;
971 strncpy (secprint, secname, seclen);
972 secprint[seclen] =
'\0';
973 error (
_(
"Section %s not found"), secprint);
1020 error (
_(
"Can't create a corefile"));
1032 Specify the filename of the executable file.";
1057 Use FILE as program to be debugged.\n\
1058 It is read for its symbols, for getting the contents of pure memory,\n\
1059 and it is the program executed when you use the `run' command.\n\
1060 If FILE cannot be found as specified, your execution directory path\n\
1061 ($PATH) is searched for a command of that name.\n\
1062 No arg means to have no executable file and no symbols."), &
cmdlist);
1067 Use FILE as program for getting contents of pure memory.\n\
1068 If FILE cannot be found as specified, your execution directory path\n\
1069 is searched for a command of that name.\n\
1070 No arg means have no executable file."), &
cmdlist);
1074 Change the base address of section SECTION of the exec file to ADDR.\n\
1075 This can be used if the exec file does not contain section addresses,\n\
1076 (such as in the a.out format), or when the addresses specified in the\n\
1077 file itself are wrong. Each section must be changed separately. The\n\
1078 ``info files'' command lists all the sections and their addresses."));
1081 Set writing into executable and core files."),
_(
"\
1082 Show writing into executable and core files."), NULL,
struct cleanup * make_cleanup_freeargv(char **arg)
char * gdb_realpath(const char *filename)
int source_full_path_of(const char *, char **)
int(* to_find_memory_regions)(struct target_ops *, find_memory_region_ftype func, void *data) TARGET_DEFAULT_FUNC(dummy_find_memory_regions)
static void exec_close_1(struct target_ops *self)
struct target_section * sections_end
struct bfd_section * the_bfd_section
int(* to_has_memory)(struct target_ops *)
void warning(const char *fmt,...)
int query(const char *ctlstr,...)
static char * exec_make_note_section(struct target_ops *self, bfd *obfd, int *note_size)
void push_target(struct target_ops *t)
int(* to_insert_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_FUNC(memory_insert_breakpoint)
int build_section_table(struct bfd *some_bfd, struct target_section **start, struct target_section **end)
hook_type deprecated_exec_file_display_hook
int unpush_target(struct target_ops *t)
void internal_error(const char *file, int line, const char *fmt,...)
#define obj_section_endaddr(s)
void(* to_close)(struct target_ops *)
#define ALL_OBJFILE_OSECTIONS(objfile, osect)
#define VEC_safe_push(T, V, O)
void observer_notify_executable_changed(void)
struct cmd_list_element * cmdlist
int(* to_remove_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_FUNC(memory_remove_breakpoint)
#define target_pid_to_exec_file(pid)
struct bfd * gdb_bfd_open(const char *name, const char *target, int fd)
enum target_xfer_status section_table_xfer_memory_partial(gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len, struct target_section *sections, struct target_section *sections_end, const char *section_name)
void printf_filtered(const char *format,...)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static void exec_file_command(char *args, int from_tty)
void set_current_program_space(struct program_space *pspace)
void(* to_files_info)(struct target_ops *) TARGET_DEFAULT_IGNORE()
static void show_write_files(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
#define TARGET_SYSROOT_PREFIX
#define obj_section_addr(s)
void gdb_bfd_ref(struct bfd *abfd)
static struct target_ops exec_ops
static void set_section_command(char *, int)
struct cmd_list_element * setlist
#define VEC_iterate(T, V, I, P)
int mem_ranges_overlap(CORE_ADDR start1, int len1, CORE_ADDR start2, int len2)
void exec_file_clear(int from_tty)
#define OPF_TRY_CWD_FIRST
char * gdb_realpath_keepfile(const char *filename)
static void add_to_section_table(bfd *abfd, struct bfd_section *asect, void *table_pp_char)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
void gdb_bfd_unref(struct bfd *abfd)
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
void set_gdbarch_from_file(bfd *abfd)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
int openp(const char *, int, const char *, int, char **)
static struct target_section_table * exec_get_section_table(struct target_ops *ops)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
static int exec_has_memory(struct target_ops *ops)
struct target_section_table target_sections
#define current_target_sections
void remove_target_sections(void *owner)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
bfd * gdb_bfd_fopen(const char *filename, const char *target, const char *mode, int fd)
struct cmd_list_element * showlist
#define target_filesystem_is_local()
struct target_section_table *(* to_get_section_table)(struct target_ops *) TARGET_DEFAULT_RETURN(NULL)
void puts_filtered(const char *string)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
static enum target_xfer_status exec_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
struct target_section * sections
void add_target_with_completer(struct target_ops *t, completer_ftype *completer)
void exec_file_locate_attach(int pid, int from_tty)
enum target_xfer_status exec_read_partial_read_only(gdb_byte *readbuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
static void file_command(char *, int)
int gdbarch_addr_bit(struct gdbarch *gdbarch)
#define target_has_execution
enum target_xfer_status(* to_xfer_partial)(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
void wrap_here(char *indent)
const char * gdb_bfd_errmsg(bfd_error_type error_tag, char **matching)
void printf_unfiltered(const char *format,...)
struct bfd_section * the_bfd_section
struct cleanup * make_cleanup_bfd_unref(bfd *abfd)
char *(* to_make_corefile_notes)(struct target_ops *, bfd *, int *) TARGET_DEFAULT_FUNC(dummy_make_corefile_notes)
enum target_xfer_status section_table_read_available_memory(gdb_byte *readbuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
int target_is_pushed(struct target_ops *t)
void symbol_file_add_main(const char *args, int from_tty)
int objfile_find_memory_regions(struct target_ops *self, find_memory_region_ftype func, void *obfd)
void exec_set_section_address(const char *filename, int index, CORE_ADDR address)
PTR xrealloc(PTR ptr, size_t size)
void exec_file_attach(const char *filename, int from_tty)
struct gdbarch * gdbarch_from_bfd(bfd *abfd)
static int resize_section_table(struct target_section_table *table, int adjustment)
char * hex_string_custom(LONGEST num, int width)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
#define ALL_PSPACES(pspace)
CORE_ADDR parse_and_eval_address(const char *exp)
void add_target_sections(void *owner, struct target_section *sections, struct target_section *sections_end)
void symbol_file_command(char *, int)
void(* deprecated_file_changed_hook)(char *)
void(* to_open)(const char *, int)
void validate_files(void)
char ** gdb_buildargv(const char *s)
char * exec_file_find(char *in_pathname, int *fd)
static void init_exec_ops(void)
void normalize_mem_ranges(VEC(mem_range_s)*ranges)
const char * to_shortname
char * get_exec_file(int err)
struct target_section_table * target_get_section_table(struct target_ops *target)
unsigned long long ULONGEST
struct cleanup * save_current_program_space(void)
static void exec_files_info(struct target_ops *)
void add_target_sections_of_objfile(struct objfile *objfile)
void target_preopen(int from_tty)
static void exec_open(const char *args, int from_tty)
void _initialize_exec(void)
int is_target_filename(const char *name)
void clear_section_table(struct target_section_table *table)
void error(const char *fmt,...)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int int rusage_t pid_t pid
void print_section_info(struct target_section_table *t, bfd *abfd)
void do_cleanups(struct cleanup *old_chain)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
const ULONGEST const LONGEST len