Commit | Line | Data |
---|---|---|
bba2d28d AC |
1 | /* Very simple "bfd" target, for GDB, the GNU debugger. |
2 | ||
3666a048 | 3 | Copyright (C) 2003-2021 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" | |
4de283e4 | 21 | #include "target.h" |
bba2d28d | 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 | |
28 | static const target_info target_bfd_target_info = { | |
29 | "bfd", | |
30 | N_("BFD backed target"), | |
31 | N_("You should never see this") | |
32 | }; | |
33 | ||
f6ac5f3d | 34 | class target_bfd : public target_ops |
891e7584 | 35 | { |
f6ac5f3d | 36 | public: |
15908a11 | 37 | explicit target_bfd (const gdb_bfd_ref_ptr &bfd); |
f6ac5f3d | 38 | |
d9f719f1 PA |
39 | const target_info &info () const override |
40 | { return target_bfd_target_info; } | |
f6ac5f3d | 41 | |
66b4deae PA |
42 | strata stratum () const override { return file_stratum; } |
43 | ||
f6ac5f3d PA |
44 | void close () override; |
45 | ||
46 | target_xfer_status | |
47 | xfer_partial (target_object object, | |
48 | const char *annex, gdb_byte *readbuf, | |
49 | const gdb_byte *writebuf, | |
50 | ULONGEST offset, ULONGEST len, | |
51 | ULONGEST *xfered_len) override; | |
52 | ||
19cf757a | 53 | const target_section_table *get_section_table () override; |
f6ac5f3d PA |
54 | |
55 | private: | |
891e7584 | 56 | /* The BFD we're wrapping. */ |
ade72a34 | 57 | gdb_bfd_ref_ptr m_bfd; |
891e7584 PA |
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. */ | |
d7a78e5c | 62 | target_section_table m_table; |
891e7584 PA |
63 | }; |
64 | ||
f6ac5f3d PA |
65 | target_xfer_status |
66 | target_bfd::xfer_partial (target_object object, | |
67 | const char *annex, gdb_byte *readbuf, | |
68 | const gdb_byte *writebuf, | |
69 | ULONGEST offset, ULONGEST len, | |
70 | ULONGEST *xfered_len) | |
bba2d28d AC |
71 | { |
72 | switch (object) | |
73 | { | |
74 | case TARGET_OBJECT_MEMORY: | |
07b82ea5 | 75 | { |
891e7584 | 76 | return section_table_xfer_memory_partial (readbuf, writebuf, |
9b409511 | 77 | offset, len, xfered_len, |
bb2a6777 | 78 | m_table); |
07b82ea5 | 79 | } |
bba2d28d | 80 | default: |
2ed4b548 | 81 | return TARGET_XFER_E_IO; |
bba2d28d AC |
82 | } |
83 | } | |
84 | ||
19cf757a | 85 | const target_section_table * |
f6ac5f3d | 86 | target_bfd::get_section_table () |
07b82ea5 | 87 | { |
f6ac5f3d | 88 | return &m_table; |
07b82ea5 PA |
89 | } |
90 | ||
15908a11 TT |
91 | target_bfd::target_bfd (const gdb_bfd_ref_ptr &abfd) |
92 | : m_bfd (abfd), | |
93 | m_table (build_section_table (abfd.get ())) | |
bba2d28d | 94 | { |
bba2d28d AC |
95 | } |
96 | ||
f6ac5f3d | 97 | target_ops * |
15908a11 | 98 | target_bfd_reopen (const gdb_bfd_ref_ptr &abfd) |
bba2d28d | 99 | { |
f6ac5f3d PA |
100 | return new target_bfd (abfd); |
101 | } | |
07b82ea5 | 102 | |
f6ac5f3d PA |
103 | void |
104 | target_bfd::close () | |
105 | { | |
106 | delete this; | |
bba2d28d | 107 | } |