GDB (xrefs)
Loading...
Searching...
No Matches
bfd-target.c
Go to the documentation of this file.
1/* Very simple "bfd" target, for GDB, the GNU debugger.
2
3 Copyright (C) 2003-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "target.h"
22#include "bfd-target.h"
23#include "exec.h"
24#include "gdb_bfd.h"
25
26/* A target that wraps a BFD. */
27
29 "bfd",
30 N_("BFD backed target"),
31 N_("You should never see this")
32};
33
34class target_bfd : public target_ops
35{
36public:
37 explicit target_bfd (const gdb_bfd_ref_ptr &bfd);
38
39 const target_info &info () const override
40 { return target_bfd_target_info; }
41
42 strata stratum () const override { return file_stratum; }
43
44 void close () override;
45
48 const char *annex, gdb_byte *readbuf,
49 const gdb_byte *writebuf,
50 ULONGEST offset, ULONGEST len,
51 ULONGEST *xfered_len) override;
52
53 const target_section_table *get_section_table () override;
54
55private:
56 /* The BFD we're wrapping. */
58
59 /* The section table build from the ALLOC sections in BFD. Note
60 that we can't rely on extracting the BFD from a random section in
61 the table, since the table can be legitimately empty. */
63};
64
67 const char *annex, gdb_byte *readbuf,
68 const gdb_byte *writebuf,
69 ULONGEST offset, ULONGEST len,
70 ULONGEST *xfered_len)
71{
72 switch (object)
73 {
75 {
76 return section_table_xfer_memory_partial (readbuf, writebuf,
77 offset, len, xfered_len,
78 m_table);
79 }
80 default:
81 return TARGET_XFER_E_IO;
82 }
83}
84
90
92 : m_bfd (abfd),
93 m_table (build_section_table (abfd.get ()))
94{
95}
96
99{
100 return target_ops_up (new target_bfd (abfd));
101}
102
103void
105{
106 delete this;
107}
constexpr string_view get()
Definition 70483.cc:49
static const target_info target_bfd_target_info
Definition bfd-target.c:28
target_ops_up target_bfd_reopen(const gdb_bfd_ref_ptr &abfd)
Definition bfd-target.c:98
target_bfd(const gdb_bfd_ref_ptr &bfd)
Definition bfd-target.c:91
const target_info & info() const override
Definition bfd-target.c:39
void close() override
Definition bfd-target.c:104
target_xfer_status xfer_partial(target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
Definition bfd-target.c:66
strata stratum() const override
Definition bfd-target.c:42
const target_section_table * get_section_table() override
Definition bfd-target.c:86
gdb_bfd_ref_ptr m_bfd
Definition bfd-target.c:57
target_section_table m_table
Definition bfd-target.c:62
enum target_xfer_status section_table_xfer_memory_partial(gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len, const target_section_table &sections, gdb::function_view< bool(const struct target_section *)> match_cb)
Definition exec.c:819
target_section_table build_section_table(struct bfd *some_bfd)
Definition exec.c:572
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
Definition gdb_bfd.h:79
std::vector< target_section > target_section_table
target_xfer_status
Definition target.h:219
@ TARGET_XFER_E_IO
Definition target.h:232
target_object
Definition target.h:143
@ TARGET_OBJECT_MEMORY
Definition target.h:147
strata
Definition target.h:94
@ file_stratum
Definition target.h:96
std::unique_ptr< target_ops, target_ops_deleter > target_ops_up
Definition target.h:1347