30 #define MAP_FAILED ((void *) -1) 34 #include "gdb/fileio.h" 64 :
mtime (bfd_get_mtime (abfd)),
65 size (bfd_get_size (abfd)),
72 if (bfd_stat (abfd, &buf) == 0)
128 #define GDB_BFD_DATA_ACCESSOR(ABFD) \ 129 ((struct gdb_bfd_data *) bfd_usrdata (ABFD)) 181 const bfd *abfd = (
const struct bfd *) b;
184 return htab_hash_string (bfd_get_filename (abfd));
193 const bfd *abfd = (
const struct bfd *) a;
202 && strcmp (bfd_get_filename (abfd), s->
filename) == 0);
269 case FILEIO_ENAMETOOLONG:
282 const char *filename = bfd_get_filename (abfd);
283 int fd, target_errno;
296 bfd_set_error (bfd_error_system_call);
300 stream =
XCNEW (
int);
310 file_ptr nbytes, file_ptr
offset)
312 int fd = *(
int *) stream;
322 nbytes - pos,
offset + pos,
330 bfd_set_error (bfd_error_system_call);
346 int fd = *(
int *) stream;
366 int fd = *(
int *) stream;
374 bfd_set_error (bfd_error_system_call);
417 bfd_set_error (bfd_error_system_call);
423 if (fstat (fd, &st) < 0)
433 search.
mtime = st.st_mtime;
434 search.
size = st.st_size;
435 search.
inode = st.st_ino;
449 "Reusing cached bfd %s for %s\n",
451 bfd_get_filename (abfd));
456 abfd = bfd_fopen (
name, target, FOPEN_RB, fd);
462 "Creating new bfd %s for %s\n",
464 bfd_get_filename (abfd));
485 if (sect != NULL && sect->
data != NULL)
507 char *
name = bfd_get_filename (abfd);
511 ret = bfd_close (abfd);
514 warning (
_(
"cannot close \"%s\": %s"),
515 name, bfd_errmsg (bfd_get_error ()));
535 "Increase reference count on bfd %s (%s)\n",
537 bfd_get_filename (abfd));
546 abfd->flags |= BFD_DECOMPRESS;
549 bfd_usrdata (abfd) = gdata;
550 bfd_alloc_data (abfd);
553 slot = htab_find_slot (
all_bfds, abfd, INSERT);
578 "Decrease reference count on bfd %s (%s)\n",
580 bfd_get_filename (abfd));
586 "Delete final reference count on bfd %s (%s)\n",
588 bfd_get_filename (abfd));
591 search.
filename = bfd_get_filename (abfd);
609 bfd_free_data (abfd);
611 bfd_usrdata (abfd) = NULL;
630 bfd_get_section_userdata (section->owner, section));
635 bfd_zalloc (section->owner, sizeof (*result)));
636 bfd_set_section_userdata (section->owner, section, result);
659 if (descriptor->
data != NULL)
663 if (!bfd_is_section_compressed (abfd, sectp))
669 pagesize = getpagesize ();
674 if (bfd_get_section_size (sectp) > 4 * pagesize)
676 descriptor->
size = bfd_get_section_size (sectp);
677 descriptor->
data = bfd_mmap (abfd, 0, descriptor->
size, PROT_READ,
678 MAP_PRIVATE, sectp->filepos,
684 #if HAVE_POSIX_MADVISE 686 POSIX_MADV_WILLNEED);
692 memset (descriptor, 0,
sizeof (*descriptor));
700 descriptor->
size = bfd_get_section_size (sectp);
701 descriptor->
data = NULL;
704 if (!bfd_get_full_section_contents (abfd, sectp, &
data))
705 error (
_(
"Can't read data for section '%s' in file '%s'"),
706 bfd_get_section_name (abfd, sectp),
707 bfd_get_filename (abfd));
723 unsigned long file_crc = 0;
725 if (bfd_seek (abfd, 0,
SEEK_SET) != 0)
727 warning (
_(
"Problem reading \"%s\" for CRC: %s"),
728 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
738 if (count == (bfd_size_type) -1)
740 warning (
_(
"Problem reading \"%s\" for CRC: %s"),
741 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
746 file_crc = bfd_calc_gnu_debuglink_crc32 (file_crc,
buffer, count);
749 *file_crc_return = file_crc;
764 *crc_out = gdata->
crc;
776 bfd *result = bfd_fopen (filename, target, mode, fd);
786 bfd *result = bfd_openr (filename, target);
796 bfd *result = bfd_openw (filename, target);
805 void *(*open_func) (
struct bfd *nbfd,
808 file_ptr (*pread_func) (
struct bfd *nbfd,
813 int (*close_func) (
struct bfd *nbfd,
815 int (*stat_func) (
struct bfd *abfd,
819 bfd *result = bfd_openr_iovec (filename, target,
820 open_func, open_closure,
821 pread_func, close_func, stat_func);
852 bfd *result = bfd_openr_next_archived_file (archive, previous);
876 bfd *result = bfd_fdopenr (filename, target, fd);
892 else if (section == bfd_com_section_ptr)
893 return bfd_count_sections (abfd);
894 else if (section == bfd_und_section_ptr)
895 return bfd_count_sections (abfd) + 1;
896 else if (section == bfd_abs_section_ptr)
897 return bfd_count_sections (abfd) + 2;
898 else if (section == bfd_ind_section_ptr)
899 return bfd_count_sections (abfd) + 3;
900 return section->index;
908 return bfd_count_sections (abfd) + 4;
922 for (sect = abfd->sections; sect != NULL; sect = sect->next)
923 if ((sect->flags & SEC_RELOC) != 0)
942 bfd *abfd = (
struct bfd *) *slot;
949 uiout->
field_string (
"filename", bfd_get_filename (abfd));
974 all_bfds = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
978 List the BFDs that are currently open."),
983 Set whether gdb will share bfds that appear to be the same file."),
_(
"\ 984 Show whether gdb will share bfds that appear to be the same file."),
_(
"\ 985 When enabled gdb will reuse existing bfds rather than reopening the\n\ 986 same file. To decide if two files are the same then gdb compares the\n\ 987 filename, file size, file modification time, and file inode."),
995 Set bfd cache debugging."),
_(
"\ 996 Show bfd cache debugging."),
_(
"\ 997 When non-zero, bfd cache specific debugging is enabled."),
void _initialize_gdb_bfd(void)
static hashval_t hash_bfd(const void *b)
#define DEFINE_REGISTRY(TAG, ACCESS)
void field_string(const char *fldname, const char *string)
void gdb_bfd_mark_parent(bfd *child, bfd *parent)
int gdb_bfd_section_index(bfd *abfd, asection *section)
std::vector< gdb_bfd_ref_ptr > included_bfds
void warning(const char *fmt,...)
int gdb_bfd_requires_relocations(bfd *abfd)
struct cmd_list_element * maintenanceinfolist
void * memset(T *s, int c, size_t n)=delete
void table_header(int width, ui_align align, const std::string &col_name, const std::string &col_hdr)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
static int print_one_bfd(void **slot, void *data)
void text(const char *string)
struct cmd_list_element * maintenance_set_cmdlist
static int gdb_bfd_iovec_fileio_close(struct bfd *abfd, void *stream)
int target_fileio_close(int fd, int *target_errno)
static unsigned int debug_bfd_cache
int gdb_bfd_crc(struct bfd *abfd, unsigned long *crc_out)
void gdb_bfd_record_inclusion(bfd *includer, bfd *includee)
#define host_address_to_string(ADDR)
#define TARGET_SYSROOT_PREFIX
void gdb_bfd_ref(struct bfd *abfd)
static gdb_bfd_ref_ptr new_bfd_ref(struct bfd *abfd)
void add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned 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)
static int eq_bfd(const void *a, const void *b)
gdb_bfd_ref_ptr gdb_bfd_open(const char *name, const char *target, int fd)
void gdb_bfd_unref(struct 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,...)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
#define target_filesystem_is_local()
static htab_t gdb_bfd_cache
#define GDB_BFD_DATA_ACCESSOR(ABFD)
static int startswith(const char *string, const char *pattern)
static void free_one_bfd_section(bfd *abfd, asection *sectp, void *ignore)
struct cmd_list_element * setdebuglist
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)
gdb_static_assert(ARRAY_SIZE(_bfd_std_section)==4)
static struct gdb_bfd_section_data * get_section_descriptor(asection *section)
gdb_bfd_ref_ptr gdb_bfd_openr(const char *filename, const char *target)
static int get_file_crc(bfd *abfd, unsigned long *file_crc_return)
static void maintenance_info_bfds(const char *arg, int from_tty)
void field_int(const char *fldname, int value)
gdb_bfd_ref_ptr 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))
int gdb_bfd_count_sections(bfd *abfd)
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)
unsigned int crc_computed
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)
gdb_bfd_ref_ptr gdb_bfd_openw(const char *filename, const char *target)
struct cmd_list_element * showdebuglist
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
static void show_bfd_cache_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
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)
struct cmd_list_element * maintenance_show_cmdlist
gdb_bfd_ref_ptr gdb_bfd_openr_next_archived_file(bfd *archive, bfd *previous)
int is_target_filename(const char *name)
static void show_bfd_sharing(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
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)
static void * gdb_bfd_iovec_fileio_open(struct bfd *abfd, void *inferior)
int gdb_bfd_has_target_filename(struct bfd *abfd)
gdb_bfd_ref_ptr gdb_bfd_fdopenr(const char *filename, const char *target, int fd)