30 #define MAP_FAILED ((void *) -1)
34 #include "gdb/fileio.h"
90 VEC (bfdp) *included_bfds;
96 #define GDB_BFD_DATA_ACCESSOR(ABFD) \
97 ((struct gdb_bfd_data *) bfd_usrdata (ABFD))
125 return htab_hash_string (bfd_get_filename (abfd));
139 && strcmp (bfd_get_filename (abfd), s->
filename) == 0);
206 case FILEIO_ENAMETOOLONG:
219 const char *filename = bfd_get_filename (abfd);
220 int fd, target_errno;
233 bfd_set_error (bfd_error_system_call);
237 stream = XCNEW (
int);
247 file_ptr nbytes, file_ptr offset)
249 int fd = *(
int *) stream;
259 nbytes - pos, offset + pos,
267 bfd_set_error (bfd_error_system_call);
283 int fd = *(
int *) stream;
303 int fd = *(
int *) stream;
311 bfd_set_error (bfd_error_system_call);
354 bfd_set_error (bfd_error_system_call);
360 if (fstat (fd, &st) < 0)
366 search.
mtime = st.st_mtime;
369 hash = htab_hash_string (name);
381 abfd = bfd_fopen (name, target, FOPEN_RB, fd);
385 slot = htab_find_slot_with_hash (
gdb_bfd_cache, &search, hash, INSERT);
401 if (sect != NULL && sect->
data != NULL)
423 char *
name = bfd_get_filename (abfd);
427 ret = bfd_close (abfd);
430 warning (
_(
"cannot close \"%s\": %s"),
431 name, bfd_errmsg (bfd_get_error ()));
447 gdata = bfd_usrdata (abfd);
456 abfd->flags |= BFD_DECOMPRESS;
458 gdata = bfd_zalloc (abfd,
sizeof (
struct gdb_bfd_data));
460 gdata->
mtime = bfd_get_mtime (abfd);
462 bfd_usrdata (abfd) = gdata;
464 bfd_alloc_data (abfd);
467 slot = htab_find_slot (all_bfds, abfd, INSERT);
480 bfd *archive_bfd, *included_bfd;
485 gdata = bfd_usrdata (abfd);
493 search.
filename = bfd_get_filename (abfd);
501 slot = htab_find_slot_with_hash (
gdb_bfd_cache, &search, hash,
509 VEC_iterate (bfdp, gdata->included_bfds, ix, included_bfd);
512 VEC_free (bfdp, gdata->included_bfds);
514 bfd_free_data (abfd);
515 bfd_usrdata (abfd) = NULL;
517 htab_remove_elt (all_bfds, abfd);
533 result = bfd_get_section_userdata (section->owner, section);
537 result = bfd_zalloc (section->owner, sizeof (*result));
538 bfd_set_section_userdata (section->owner, section, result);
561 if (descriptor->
data != NULL)
565 if (!bfd_is_section_compressed (abfd, sectp))
571 pagesize = getpagesize ();
576 if (bfd_get_section_size (sectp) > 4 * pagesize)
578 descriptor->
size = bfd_get_section_size (sectp);
579 descriptor->
data = bfd_mmap (abfd, 0, descriptor->
size, PROT_READ,
580 MAP_PRIVATE, sectp->filepos,
586 #if HAVE_POSIX_MADVISE
588 POSIX_MADV_WILLNEED);
594 memset (descriptor, 0,
sizeof (*descriptor));
602 descriptor->
size = bfd_get_section_size (sectp);
603 descriptor->
data = NULL;
606 if (!bfd_get_full_section_contents (abfd, sectp, &data))
607 error (
_(
"Can't read data for section '%s' in file '%s'"),
608 bfd_get_section_name (abfd, sectp),
609 bfd_get_filename (abfd));
614 *size = descriptor->
size;
615 return descriptor->
data;
625 unsigned long file_crc = 0;
627 if (bfd_seek (abfd, 0,
SEEK_SET) != 0)
629 warning (
_(
"Problem reading \"%s\" for CRC: %s"),
630 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
639 count = bfd_bread (buffer,
sizeof (buffer), abfd);
640 if (count == (bfd_size_type) -1)
642 warning (
_(
"Problem reading \"%s\" for CRC: %s"),
643 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
648 file_crc = bfd_calc_gnu_debuglink_crc32 (file_crc, buffer, count);
651 *file_crc_return = file_crc;
666 *crc_out = gdata->
crc;
678 bfd *result = bfd_fopen (filename, target, mode, fd);
691 bfd *result = bfd_openr (filename, target);
704 bfd *result = bfd_openw (filename, target);
716 void *(*open_func) (
struct bfd *nbfd,
719 file_ptr (*pread_func) (
struct bfd *nbfd,
724 int (*close_func) (
struct bfd *nbfd,
726 int (*stat_func) (
struct bfd *abfd,
730 bfd *result = bfd_openr_iovec (filename, target,
731 open_func, open_closure,
732 pread_func, close_func, stat_func);
751 gdata = bfd_usrdata (child);
766 bfd *result = bfd_openr_next_archived_file (archive, previous);
782 gdata = bfd_usrdata (includer);
791 bfd *result = bfd_fdopenr (filename, target, fd);
810 else if (section == bfd_com_section_ptr)
811 return bfd_count_sections (abfd);
812 else if (section == bfd_und_section_ptr)
813 return bfd_count_sections (abfd) + 1;
814 else if (section == bfd_abs_section_ptr)
815 return bfd_count_sections (abfd) + 2;
816 else if (section == bfd_ind_section_ptr)
817 return bfd_count_sections (abfd) + 3;
818 return section->index;
826 return bfd_count_sections (abfd) + 4;
840 for (sect = abfd->sections; sect != NULL; sect = sect->next)
841 if ((sect->flags & SEC_RELOC) != 0)
900 all_bfds = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
904 List the BFDs that are currently open."),
static hashval_t hash_bfd(const void *b)
#define DEFINE_REGISTRY(TAG, ACCESS)
void ui_out_field_int(struct ui_out *uiout, const char *fldname, int value)
initialize_file_ftype _initialize_gdb_bfd
void gdb_bfd_mark_parent(bfd *child, bfd *parent)
int gdb_bfd_section_index(bfd *abfd, asection *section)
void warning(const char *fmt,...)
int gdb_bfd_requires_relocations(bfd *abfd)
struct cleanup * make_cleanup_ui_out_table_begin_end(struct ui_out *ui_out, int nr_cols, int nr_rows, const char *tblid)
struct cmd_list_element * maintenanceinfolist
#define VEC_safe_push(T, V, O)
static int print_one_bfd(void **slot, void *data)
struct bfd * gdb_bfd_open(const char *name, const char *target, int fd)
static int gdb_bfd_iovec_fileio_close(struct bfd *abfd, void *stream)
int target_fileio_close(int fd, int *target_errno)
void ui_out_text(struct ui_out *uiout, const char *string)
int gdb_bfd_crc(struct bfd *abfd, unsigned long *crc_out)
void gdb_bfd_record_inclusion(bfd *includer, bfd *includee)
#define TARGET_SYSROOT_PREFIX
void gdb_bfd_ref(struct bfd *abfd)
static int eq_bfd(const void *a, const void *b)
#define VEC_iterate(T, V, I, P)
void gdb_bfd_unref(struct bfd *abfd)
void initialize_file_ftype(void)
struct cleanup * make_cleanup_ui_out_tuple_begin_end(struct ui_out *uiout, const char *id)
bfd * gdb_bfd_fdopenr(const char *filename, const char *target, int fd)
bfd * gdb_bfd_fopen(const char *filename, const char *target, const char *mode, int fd)
#define target_filesystem_is_local()
static htab_t gdb_bfd_cache
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)
#define GDB_BFD_DATA_ACCESSOR(ABFD)
bfd * gdb_bfd_openr_iovec(const char *filename, const char *target, void *(*open_func)(struct bfd *nbfd, void *open_closure), void *open_closure, file_ptr(*pread_func)(struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes, file_ptr offset), int(*close_func)(struct bfd *nbfd, void *stream), int(*stat_func)(struct bfd *abfd, void *stream, struct stat *sb))
bfd * gdb_bfd_openr_next_archived_file(bfd *archive, bfd *previous)
static int startswith(const char *string, const char *pattern)
static void maintenance_info_bfds(char *arg, int from_tty)
static void free_one_bfd_section(bfd *abfd, asection *sectp, void *ignore)
static file_ptr gdb_bfd_iovec_fileio_pread(struct bfd *abfd, void *stream, void *buf, file_ptr nbytes, file_ptr offset)
unsigned long hash(const void *addr, int length)
bfd * gdb_bfd_openw(const char *filename, const char *target)
gdb_static_assert(ARRAY_SIZE(_bfd_std_section)==4)
static struct gdb_bfd_section_data * get_section_descriptor(asection *section)
static int get_file_crc(bfd *abfd, unsigned long *file_crc_return)
int gdb_bfd_count_sections(bfd *abfd)
const char * host_address_to_string(const void *addr)
unsigned int crc_computed
void ui_out_table_header(struct ui_out *uiout, int width, enum ui_align alignment, const char *col_name, const char *colhdr)
unsigned int needs_relocations
int target_fileio_pread(int fd, gdb_byte *read_buf, int len, ULONGEST offset, int *target_errno)
int gdb_open_cloexec(const char *filename, int flags, unsigned long mode)
struct inferior * current_inferior(void)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
bfd * gdb_bfd_openr(const char *filename, const char *target)
void ui_out_field_string(struct ui_out *uiout, const char *fldname, const char *string)
const gdb_byte * gdb_bfd_map_section(asection *sectp, bfd_size_type *size)
int target_fileio_fstat(int fd, struct stat *sb, int *target_errno)
unsigned int relocation_computed
void ui_out_table_body(struct ui_out *uiout)
struct ui_out * current_uiout
static int gdb_bfd_close_or_warn(struct bfd *abfd)
PTR xcalloc(size_t number, size_t size)
static int fileio_errno_to_host(int errnum)
int is_target_filename(const char *name)
static int gdb_bfd_iovec_fileio_fstat(struct bfd *abfd, void *stream, struct stat *sb)
void error(const char *fmt,...)
int target_fileio_open_warn_if_slow(struct inferior *inf, const char *filename, int flags, int mode, int *target_errno)
void do_cleanups(struct cleanup *old_chain)
static void * gdb_bfd_iovec_fileio_open(struct bfd *abfd, void *inferior)
int gdb_bfd_has_target_filename(struct bfd *abfd)