Sort includes for files gdb/[a-f]*.[chyl].
[deliverable/binutils-gdb.git] / gdb / bfd-target.c
1 /* Very simple "bfd" target, for GDB, the GNU debugger.
2
3 Copyright (C) 2003-2019 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
22 /* Local non-gdb includes. */
23 #include "bfd-target.h"
24 #include "exec.h"
25 #include "gdb_bfd.h"
26 #include "target.h"
27
28 /* A target that wraps a BFD. */
29
30 static const target_info target_bfd_target_info = {
31 "bfd",
32 N_("BFD backed target"),
33 N_("You should never see this")
34 };
35
36 class target_bfd : public target_ops
37 {
38 public:
39 explicit target_bfd (struct bfd *bfd);
40 ~target_bfd () override;
41
42 const target_info &info () const override
43 { return target_bfd_target_info; }
44
45 strata stratum () const override { return file_stratum; }
46
47 void close () override;
48
49 target_xfer_status
50 xfer_partial (target_object object,
51 const char *annex, gdb_byte *readbuf,
52 const gdb_byte *writebuf,
53 ULONGEST offset, ULONGEST len,
54 ULONGEST *xfered_len) override;
55
56 target_section_table *get_section_table () override;
57
58 private:
59 /* The BFD we're wrapping. */
60 gdb_bfd_ref_ptr m_bfd;
61
62 /* The section table build from the ALLOC sections in BFD. Note
63 that we can't rely on extracting the BFD from a random section in
64 the table, since the table can be legitimately empty. */
65 struct target_section_table m_table;
66 };
67
68 target_xfer_status
69 target_bfd::xfer_partial (target_object object,
70 const char *annex, gdb_byte *readbuf,
71 const gdb_byte *writebuf,
72 ULONGEST offset, ULONGEST len,
73 ULONGEST *xfered_len)
74 {
75 switch (object)
76 {
77 case TARGET_OBJECT_MEMORY:
78 {
79 return section_table_xfer_memory_partial (readbuf, writebuf,
80 offset, len, xfered_len,
81 m_table.sections,
82 m_table.sections_end,
83 NULL);
84 }
85 default:
86 return TARGET_XFER_E_IO;
87 }
88 }
89
90 target_section_table *
91 target_bfd::get_section_table ()
92 {
93 return &m_table;
94 }
95
96 target_bfd::target_bfd (struct bfd *abfd)
97 : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd))
98 {
99 m_table.sections = NULL;
100 m_table.sections_end = NULL;
101 build_section_table (abfd, &m_table.sections, &m_table.sections_end);
102 }
103
104 target_bfd::~target_bfd ()
105 {
106 xfree (m_table.sections);
107 }
108
109 target_ops *
110 target_bfd_reopen (struct bfd *abfd)
111 {
112 return new target_bfd (abfd);
113 }
114
115 void
116 target_bfd::close ()
117 {
118 delete this;
119 }
This page took 0.032275 seconds and 5 git commands to generate.