/* SYMFILE_VERBOSE is not passed even if FROM_TTY, user is not interested in
"Reading symbols from ..." message for automatically generated file. */
- objfile_up objfile_holder (symbol_file_add_from_bfd (abfd,
- filename.get (),
- 0, NULL, 0, NULL));
+ scoped_objfile_unlinker objfile_holder (symbol_file_add_from_bfd
+ (abfd, filename.get (),
+ 0, NULL, 0, NULL));
objfile = objfile_holder.get ();
func_sym = lookup_global_symbol_from_objfile (objfile,
gdb_assert (section->owner == nullptr || section->owner == this->obfd);
int idx = gdb_bfd_section_index (this->obfd.get (), section);
+
+ /* Guarantee that the section offsets were initialized. */
+ gdb_assert (this->section_offsets.size () > idx);
return this->section_offsets[idx];
}
gdb_assert (section->owner == nullptr || section->owner == this->obfd);
int idx = gdb_bfd_section_index (this->obfd.get (), section);
+
+ /* Guarantee that the section offsets were initialized. */
+ gdb_assert (this->section_offsets.capacity () > idx);
this->section_offsets[idx] = offset;
}
/* A deleter for objfile. */
-struct objfile_deleter
+struct objfile_unlinker
{
void operator() (objfile *ptr) const
{
/* A unique pointer that holds an objfile. */
-typedef std::unique_ptr<objfile, objfile_deleter> objfile_up;
+typedef std::unique_ptr<objfile, objfile_unlinker> scoped_objfile_unlinker;
/* Relocation offset applied to the section. */
inline CORE_ADDR
section_addr_info local_addr;
const int mainline = add_flags & SYMFILE_MAINLINE;
+ /* If we can't find a sym_fns struct to read the objfile, we'll error
+ out, and should unlink the objfile from the program space. So this
+ should be declared before a find_sym_fns call. */
+ scoped_objfile_unlinker objfile_holder (objfile);
+
objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd.get ()));
objfile->qf.clear ();
if an error occurs during symbol reading. */
std::optional<clear_symtab_users_cleanup> defer_clear_users;
- objfile_up objfile_holder (objfile);
-
/* If ADDRS is NULL, put together a dummy address list.
We now establish the convention that an addr of zero means
no load address was specified. */
/* If we get an error, blow away this objfile (not sure if
that is the correct response for things like shared
libraries). */
- objfile_up objfile_holder (objfile);
+ scoped_objfile_unlinker objfile_holder (objfile);
/* We need to do this whenever any symbols go away. */
clear_symtab_users_cleanup defer_clear_users (0);