26 #include "filenames.h" 40 #include "readline/readline.h" 134 symfile_add_flags add_flags)
160 if (
err.message != NULL)
166 if (
err.message != NULL)
171 if (exec_file_host != NULL)
193 char *exec_file_target, *exec_file_host;
195 symfile_add_flags add_flags = 0;
203 if (exec_file_target == NULL)
205 warning (
_(
"No executable has been specified and target does not " 207 "determining executable automatically. " 208 "Try using the \"file\" command."));
265 int load_via_target = 0;
266 const char *scratch_pathname, *canonical_pathname;
284 warning (
_(
"writing into executable files is " 285 "not supported for %s sysroots"),
288 scratch_pathname = filename;
290 canonical_pathname = scratch_pathname;
300 #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__) 301 if (scratch_chan < 0)
303 char *exename = (
char *) alloca (strlen (filename) + 5);
305 strcat (strcpy (exename, filename),
".exe");
313 if (scratch_chan < 0)
316 scratch_storage.reset (temp_pathname);
317 scratch_pathname = temp_pathname;
322 canonical_pathname = canonical_storage.get ();
328 FOPEN_RUB, scratch_chan);
335 error (
_(
"\"%s\": could not open as an executable file: %s."),
336 scratch_pathname, bfd_errmsg (bfd_get_error ()));
347 if (!bfd_check_format_matches (
exec_bfd, bfd_object, &matching))
352 error (
_(
"\"%s\": not in executable format: %s"),
362 error (
_(
"\"%s\": can't find the file sections: %s"),
363 scratch_pathname, bfd_errmsg (bfd_get_error ()));
380 (*deprecated_exec_file_display_hook) (filename);
383 bfd_cache_close_all ();
399 && !
query (
_(
"A program is being debugged already.\n" 400 "Are you sure you want to change the file? ")))
401 error (
_(
"File not changed."));
409 char **
argv = built_argv.
get ();
415 error (
_(
"No executable file name was specified"));
458 aflag = bfd_get_section_flags (abfd, asect);
459 if (!(aflag & SEC_ALLOC))
462 (*table_pp)->owner = NULL;
463 (*table_pp)->the_bfd_section = asect;
464 (*table_pp)->addr = bfd_section_vma (abfd, asect);
465 (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect);
491 new_count = adjustment + old_count;
514 count = bfd_count_sections (some_bfd);
520 if (*end > *start + count)
522 _(
"failed internal consistency check"));
545 for (i = 0; i < count; ++i)
592 gdb_assert (ts < table->sections + space + count);
616 if (src->
owner != owner)
633 if (old_count + (dest - src) == 0)
662 for (s =
exec_bfd->sections; s; s = s->next)
664 if ((s->flags & SEC_LOAD) == 0
665 || (s->flags & SEC_READONLY) == 0)
669 size = bfd_get_section_size (s);
678 amt = bfd_get_section_contents (
exec_bfd, s,
679 readbuf,
offset - vma, amt);
700 static std::vector<mem_range>
705 std::vector<mem_range> memory;
709 if ((bfd_get_section_flags (p->the_bfd_section->owner,
711 & SEC_READONLY) == 0)
726 int length = std::min (hi1, hi2) - start;
728 memory.emplace_back (start, length);
740 std::vector<mem_range> available_memory
746 for (
const mem_range &r : available_memory)
754 end = std::min<CORE_ADDR> (
offset + len, r.start + r.length);
764 *xfered_len = r.start -
offset;
781 const char *section_name)
790 _(
"failed internal consistency check"));
792 for (p = sections; p < sections_end; p++)
795 bfd *abfd = asect->owner;
797 if (section_name && strcmp (section_name, asect->name) != 0)
799 if (memaddr >= p->
addr)
801 if (memend <= p->endaddr)
805 res = bfd_set_section_contents (abfd, asect,
806 writebuf, memaddr - p->
addr,
809 res = bfd_get_section_contents (abfd, asect,
810 readbuf, memaddr - p->
addr,
821 else if (memaddr >= p->
endaddr)
831 res = bfd_set_section_contents (abfd, asect,
832 writebuf, memaddr - p->
addr,
835 res = bfd_get_section_contents (abfd, asect,
836 readbuf, memaddr - p->
addr,
860 const char *annex,
gdb_byte *readbuf,
892 bfd_vma displacement = 0;
895 for (p = t->
sections; p < t->sections_end; p++)
898 bfd *pbfd = psect->owner;
900 if ((bfd_get_section_flags (pbfd, psect) & (SEC_ALLOC | SEC_LOAD))
901 != (SEC_ALLOC | SEC_LOAD))
904 if (bfd_get_section_vma (pbfd, psect) <= abfd->start_address
905 && abfd->start_address < (bfd_get_section_vma (pbfd, psect)
906 + bfd_get_section_size (psect)))
908 displacement = p->
addr - bfd_get_section_vma (pbfd, psect);
913 warning (
_(
"Cannot find section for the entry point of %s."),
914 bfd_get_filename (abfd));
917 bfd_get_start_address (abfd)
922 for (p = t->
sections; p < t->sections_end; p++)
925 bfd *pbfd = psect->owner;
961 unsigned long secaddr;
967 error (
_(
"Must specify section name and its virtual address"));
970 for (secname = args; !isspace (*args); args++);
971 seclen = args - secname;
979 if (!strncmp (secname, bfd_section_name (p->bfd,
991 if (seclen >=
sizeof (secprint))
992 seclen =
sizeof (secprint) - 1;
993 strncpy (secprint, secname, seclen);
994 secprint[seclen] =
'\0';
995 error (
_(
"Section %s not found"), secprint);
1052 error (
_(
"Can't create a corefile"));
1064 Specify the filename of the executable file.";
1089 Use FILE as program to be debugged.\n\ 1090 It is read for its symbols, for getting the contents of pure memory,\n\ 1091 and it is the program executed when you use the `run' command.\n\ 1092 If FILE cannot be found as specified, your execution directory path\n\ 1093 ($PATH) is searched for a command of that name.\n\ 1094 No arg means to have no executable file and no symbols."), &
cmdlist);
1099 Use FILE as program for getting contents of pure memory.\n\ 1100 If FILE cannot be found as specified, your execution directory path\n\ 1101 is searched for a command of that name.\n\ 1102 No arg means have no executable file."), &
cmdlist);
1106 Change the base address of section SECTION of the exec file to ADDR.\n\ 1107 This can be used if the exec file does not contain section addresses,\n\ 1108 (such as in the a.out format), or when the addresses specified in the\n\ 1109 file itself are wrong. Each section must be changed separately. The\n\ 1110 ``info files'' command lists all the sections and their addresses."));
1113 Set writing into executable and core files."),
_(
"\ 1114 Show writing into executable and core files."), NULL,
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
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)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
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)
char * get_exec_file(int err)
static int exec_remove_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, enum remove_bp_reason reason)
hook_type deprecated_exec_file_display_hook
int exception_print_same(struct gdb_exception e1, struct gdb_exception e2)
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 *)
const struct gdb_exception exception_none
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
gdb::unique_xmalloc_ptr< char > gdb_realpath_keepfile(const char *filename)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
#define ALL_OBJFILE_OSECTIONS(objfile, osect)
void symbol_file_add_main(const char *args, symfile_add_flags add_flags)
void observer_notify_executable_changed(void)
struct cmd_list_element * cmdlist
gdb::unique_xmalloc_ptr< char > gdb_realpath(const char *filename)
#define target_pid_to_exec_file(pid)
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)
static void set_section_command(const char *args, int from_tty)
void printf_filtered(const char *format,...)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
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
static gdb_bfd_ref_ptr new_bfd_ref(struct bfd *abfd)
static struct target_ops exec_ops
struct cmd_list_element * setlist
void symbol_file_command(const char *, int)
int mem_ranges_overlap(CORE_ADDR start1, int len1, CORE_ADDR start2, int len2)
void exec_file_clear(int from_tty)
gdb_bfd_ref_ptr gdb_bfd_open(const char *name, const char *target, int fd)
#define CATCH(EXCEPTION, MASK)
#define OPF_TRY_CWD_FIRST
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
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)
gdb_bfd_ref_ptr gdb_bfd_fopen(const char *filename, const char *target, const char *mode, int fd)
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)
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)
void free_current_contents(void *ptr)
void normalize_mem_ranges(std::vector< mem_range > *memory)
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)
enum target_xfer_status exec_read_partial_read_only(gdb_byte *readbuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
static void file_command(const char *arg, int from_tty)
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)
const char * gdb_bfd_errmsg(bfd_error_type error_tag, char **matching)
void printf_unfiltered(const char *format,...)
struct bfd_section * the_bfd_section
#define XRESIZEVEC(T, P, N)
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)
int objfile_find_memory_regions(struct target_ops *self, find_memory_region_ftype func, void *obfd)
void wrap_here(const char *indent)
void exec_set_section_address(const char *filename, int index, CORE_ADDR address)
static void exec_file_command(const char *args, int from_tty)
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)
static std::vector< mem_range > section_table_available_memory(CORE_ADDR memaddr, ULONGEST len, struct target_section *sections, struct target_section *sections_end)
void exec_file_locate_attach(int pid, int defer_bp_reset, int from_tty)
void add_target_sections(void *owner, struct target_section *sections, struct target_section *sections_end)
#define obj_section_addr(s)
void(* to_open)(const char *, int)
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_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
char * exec_file_find(const char *in_pathname, int *fd)
void validate_files(void)
void try_open_exec_file(const char *exec_file_host, struct inferior *inf, symfile_add_flags add_flags)
static void init_exec_ops(void)
int(* to_remove_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) TARGET_DEFAULT_FUNC(memory_remove_breakpoint)
struct inferior * current_inferior(void)
const char * to_shortname
struct target_section_table * target_get_section_table(struct target_ops *target)
unsigned long long ULONGEST
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)
void(* deprecated_file_changed_hook)(const char *)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc)
int is_target_filename(const char *name)
void clear_section_table(struct target_section_table *table)
void error(const char *fmt,...)
void print_section_info(struct target_section_table *t, bfd *abfd)
void do_cleanups(struct cleanup *old_chain)