#include "gdb/fileio.h"
#include "inferior.h"
-typedef bfd *bfdp;
-DEF_VEC_P (bfdp);
-
/* An object of this type is stored in the section's user data when
mapping a section. */
struct gdb_bfd_data
{
+ gdb_bfd_data (bfd *abfd)
+ : mtime (bfd_get_mtime (abfd)),
+ size (bfd_get_size (abfd)),
+ relocation_computed (0),
+ needs_relocations (0),
+ crc_computed (0)
+ {
+ struct stat buf;
+
+ if (bfd_stat (abfd, &buf) == 0)
+ {
+ inode = buf.st_ino;
+ device_id = buf.st_dev;
+ }
+ else
+ {
+ /* The stat failed. */
+ inode = 0;
+ device_id = 0;
+ }
+ }
+
+ ~gdb_bfd_data ()
+ {
+ }
+
/* The reference count. */
- int refc;
+ int refc = 1;
/* The mtime of the BFD at the point the cache entry was made. */
time_t mtime;
unsigned int crc_computed : 1;
/* The file's CRC. */
- unsigned long crc;
+ unsigned long crc = 0;
/* If the BFD comes from an archive, this points to the archive's
BFD. Otherwise, this is NULL. */
- bfd *archive_bfd;
+ bfd *archive_bfd = nullptr;
/* Table of all the bfds this bfd has included. */
- VEC (bfdp) *included_bfds;
+ std::vector<gdb_bfd_ref_ptr> included_bfds;
/* The registry. */
- REGISTRY_FIELDS;
+ REGISTRY_FIELDS = {};
};
#define GDB_BFD_DATA_ACCESSOR(ABFD) \
void
gdb_bfd_ref (struct bfd *abfd)
{
- struct stat buf;
struct gdb_bfd_data *gdata;
void **slot;
/* Ask BFD to decompress sections in bfd_get_full_section_contents. */
abfd->flags |= BFD_DECOMPRESS;
- gdata
- = (struct gdb_bfd_data *) bfd_zalloc (abfd, sizeof (struct gdb_bfd_data));
- gdata->refc = 1;
- gdata->mtime = bfd_get_mtime (abfd);
- gdata->size = bfd_get_size (abfd);
- gdata->archive_bfd = NULL;
- if (bfd_stat (abfd, &buf) == 0)
- {
- gdata->inode = buf.st_ino;
- gdata->device_id = buf.st_dev;
- }
- else
- {
- /* The stat failed. */
- gdata->inode = 0;
- gdata->device_id = 0;
- }
+ gdata = new gdb_bfd_data (abfd);
bfd_usrdata (abfd) = gdata;
-
bfd_alloc_data (abfd);
/* This is the first we've seen it, so add it to the hash table. */
void
gdb_bfd_unref (struct bfd *abfd)
{
- int ix;
struct gdb_bfd_data *gdata;
struct gdb_bfd_cache_search search;
- bfd *archive_bfd, *included_bfd;
+ bfd *archive_bfd;
if (abfd == NULL)
return;
htab_clear_slot (gdb_bfd_cache, slot);
}
- for (ix = 0;
- VEC_iterate (bfdp, gdata->included_bfds, ix, included_bfd);
- ++ix)
- gdb_bfd_unref (included_bfd);
- VEC_free (bfdp, gdata->included_bfds);
-
bfd_free_data (abfd);
+ delete gdata;
bfd_usrdata (abfd) = NULL; /* Paranoia. */
htab_remove_elt (all_bfds, abfd);
{
struct gdb_bfd_data *gdata;
- gdb_bfd_ref (includee);
gdata = (struct gdb_bfd_data *) bfd_usrdata (includer);
- VEC_safe_push (bfdp, gdata->included_bfds, includee);
+ gdata->included_bfds.push_back (new_bfd_ref (includee));
}
/* See gdb_bfd.h. */