/* Very simple "bfd" target, for GDB, the GNU debugger.
- Copyright (C) 2003-2018 Free Software Foundation, Inc.
+ Copyright (C) 2003-2023 Free Software Foundation, Inc.
This file is part of GDB.
class target_bfd : public target_ops
{
public:
- explicit target_bfd (struct bfd *bfd);
- ~target_bfd () override;
+ explicit target_bfd (const gdb_bfd_ref_ptr &bfd);
const target_info &info () const override
{ return target_bfd_target_info; }
+ strata stratum () const override { return file_stratum; }
+
void close () override;
target_xfer_status
ULONGEST offset, ULONGEST len,
ULONGEST *xfered_len) override;
- target_section_table *get_section_table () override;
+ const target_section_table *get_section_table () override;
private:
/* The BFD we're wrapping. */
/* The section table build from the ALLOC sections in BFD. Note
that we can't rely on extracting the BFD from a random section in
the table, since the table can be legitimately empty. */
- struct target_section_table m_table;
+ target_section_table m_table;
};
target_xfer_status
{
return section_table_xfer_memory_partial (readbuf, writebuf,
offset, len, xfered_len,
- m_table.sections,
- m_table.sections_end,
- NULL);
+ m_table);
}
default:
return TARGET_XFER_E_IO;
}
}
-target_section_table *
+const target_section_table *
target_bfd::get_section_table ()
{
return &m_table;
}
-target_bfd::target_bfd (struct bfd *abfd)
- : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
-{
- this->to_stratum = file_stratum;
- m_table.sections = NULL;
- m_table.sections_end = NULL;
- build_section_table (abfd, &m_table.sections, &m_table.sections_end);
-}
-
-target_bfd::~target_bfd ()
+target_bfd::target_bfd (const gdb_bfd_ref_ptr &abfd)
+ : m_bfd (abfd),
+ m_table (build_section_table (abfd.get ()))
{
- xfree (m_table.sections);
}
target_ops *
-target_bfd_reopen (struct bfd *abfd)
+target_bfd_reopen (const gdb_bfd_ref_ptr &abfd)
{
return new target_bfd (abfd);
}