Add PR number to previous delta to the bfd/ directory.
[deliverable/binutils-gdb.git] / gdb / bfd-target.c
CommitLineData
bba2d28d
AC
1/* Very simple "bfd" target, for GDB, the GNU debugger.
2
e2882c85 3 Copyright (C) 2003-2018 Free Software Foundation, Inc.
bba2d28d
AC
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
bba2d28d
AC
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
bba2d28d
AC
19
20#include "defs.h"
21#include "target.h"
22#include "bfd-target.h"
348f8c02 23#include "exec.h"
cbb099e8 24#include "gdb_bfd.h"
bba2d28d 25
f6ac5f3d 26/* A target that wraps a BFD. */
d9f719f1
PA
27
28static const target_info target_bfd_target_info = {
29 "bfd",
30 N_("BFD backed target"),
31 N_("You should never see this")
32};
33
f6ac5f3d 34class target_bfd : public target_ops
891e7584 35{
f6ac5f3d
PA
36public:
37 explicit target_bfd (struct bfd *bfd);
38 ~target_bfd () override;
39
d9f719f1
PA
40 const target_info &info () const override
41 { return target_bfd_target_info; }
f6ac5f3d
PA
42
43 void close () override;
44
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;
51
52 target_section_table *get_section_table () override;
53
54private:
891e7584 55 /* The BFD we're wrapping. */
ade72a34 56 gdb_bfd_ref_ptr m_bfd;
891e7584
PA
57
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. */
f6ac5f3d 61 struct target_section_table m_table;
891e7584
PA
62};
63
f6ac5f3d
PA
64target_xfer_status
65target_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)
bba2d28d
AC
70{
71 switch (object)
72 {
73 case TARGET_OBJECT_MEMORY:
07b82ea5 74 {
891e7584 75 return section_table_xfer_memory_partial (readbuf, writebuf,
9b409511 76 offset, len, xfered_len,
f6ac5f3d
PA
77 m_table.sections,
78 m_table.sections_end,
07b82ea5
PA
79 NULL);
80 }
bba2d28d 81 default:
2ed4b548 82 return TARGET_XFER_E_IO;
bba2d28d
AC
83 }
84}
85
f6ac5f3d
PA
86target_section_table *
87target_bfd::get_section_table ()
07b82ea5 88{
f6ac5f3d 89 return &m_table;
07b82ea5
PA
90}
91
f6ac5f3d 92target_bfd::target_bfd (struct bfd *abfd)
ade72a34 93 : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
bba2d28d 94{
f6ac5f3d 95 this->to_stratum = file_stratum;
f6ac5f3d
PA
96 m_table.sections = NULL;
97 m_table.sections_end = NULL;
98 build_section_table (abfd, &m_table.sections, &m_table.sections_end);
99}
891e7584 100
f6ac5f3d
PA
101target_bfd::~target_bfd ()
102{
f6ac5f3d 103 xfree (m_table.sections);
bba2d28d
AC
104}
105
f6ac5f3d 106target_ops *
ad13d8df 107target_bfd_reopen (struct bfd *abfd)
bba2d28d 108{
f6ac5f3d
PA
109 return new target_bfd (abfd);
110}
07b82ea5 111
f6ac5f3d
PA
112void
113target_bfd::close ()
114{
115 delete this;
bba2d28d 116}
This page took 1.254663 seconds and 4 git commands to generate.