gdb/testsuite: gdb.base/args.exp: add KFAIL for native-extended-gdbserver
[binutils-gdb.git] / gdb / bfd-target.c
index ffe85ae3e0e648747295655474a1ae8967587816..b23cf2cd5ccb63c303db1c43d60903bcdc88c1a4 100644 (file)
@@ -1,6 +1,6 @@
 /* Very simple "bfd" target, for GDB, the GNU debugger.
 
-   Copyright (C) 2003-2019 Free Software Foundation, Inc.
+   Copyright (C) 2003-2021 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -34,8 +34,7 @@ static const target_info target_bfd_target_info = {
 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; }
@@ -51,7 +50,7 @@ public:
                  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.  */
@@ -60,7 +59,7 @@ private:
   /* 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
@@ -76,36 +75,27 @@ target_bfd::xfer_partial (target_object object,
       {
        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))
+target_bfd::target_bfd (const gdb_bfd_ref_ptr &abfd)
+  : m_bfd (abfd),
+    m_table (build_section_table (abfd.get ()))
 {
-  m_table.sections = NULL;
-  m_table.sections_end = NULL;
-  build_section_table (abfd, &m_table.sections, &m_table.sections_end);
-}
-
-target_bfd::~target_bfd ()
-{
-  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);
 }