Fix building Loongarch BFD with a 32-bit compiler
[binutils-gdb.git] / gdb / bfd-target.c
blob96e045e4e52f293fc984d1dae049ebfc82a7c8a8
1 /* Very simple "bfd" target, for GDB, the GNU debugger.
3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "target.h"
21 #include "bfd-target.h"
22 #include "exec.h"
23 #include "gdb_bfd.h"
25 /* A target that wraps a BFD. */
27 static const target_info target_bfd_target_info = {
28 "bfd",
29 N_("BFD backed target"),
30 N_("You should never see this")
33 class target_bfd : public target_ops
35 public:
36 explicit target_bfd (const gdb_bfd_ref_ptr &bfd);
38 const target_info &info () const override
39 { return target_bfd_target_info; }
41 strata stratum () const override { return file_stratum; }
43 void close () override;
45 target_xfer_status
46 xfer_partial (target_object object,
47 const char *annex, gdb_byte *readbuf,
48 const gdb_byte *writebuf,
49 ULONGEST offset, ULONGEST len,
50 ULONGEST *xfered_len) override;
52 const std::vector<target_section> *get_section_table () override;
54 private:
55 /* The BFD we're wrapping. */
56 gdb_bfd_ref_ptr m_bfd;
58 /* The section table build from the ALLOC sections in BFD. Note
59 that we can't rely on extracting the BFD from a random section in
60 the table, since the table can be legitimately empty. */
61 std::vector<target_section> m_table;
64 target_xfer_status
65 target_bfd::xfer_partial (target_object object,
66 const char *annex, gdb_byte *readbuf,
67 const gdb_byte *writebuf,
68 ULONGEST offset, ULONGEST len,
69 ULONGEST *xfered_len)
71 switch (object)
73 case TARGET_OBJECT_MEMORY:
75 return section_table_xfer_memory_partial (readbuf, writebuf,
76 offset, len, xfered_len,
77 m_table);
79 default:
80 return TARGET_XFER_E_IO;
84 const std::vector<target_section> *
85 target_bfd::get_section_table ()
87 return &m_table;
90 target_bfd::target_bfd (const gdb_bfd_ref_ptr &abfd)
91 : m_bfd (abfd),
92 m_table (build_section_table (abfd.get ()))
96 target_ops_up
97 target_bfd_reopen (const gdb_bfd_ref_ptr &abfd)
99 return target_ops_up (new target_bfd (abfd));
102 void
103 target_bfd::close ()
105 delete this;