]>
Commit | Line | Data |
---|---|---|
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 PA |
26 | /* A target that wraps a BFD. */ |
27 | class target_bfd : public target_ops | |
891e7584 | 28 | { |
f6ac5f3d PA |
29 | public: |
30 | explicit target_bfd (struct bfd *bfd); | |
31 | ~target_bfd () override; | |
32 | ||
33 | const char *shortname () override | |
34 | { return "bfd"; } | |
35 | ||
36 | const char *longname () override | |
37 | { return _("BFD backed target"); } | |
38 | ||
39 | const char *doc () override | |
40 | { return _("You should never see this"); } | |
41 | ||
42 | void close () override; | |
43 | ||
44 | target_xfer_status | |
45 | xfer_partial (target_object object, | |
46 | const char *annex, gdb_byte *readbuf, | |
47 | const gdb_byte *writebuf, | |
48 | ULONGEST offset, ULONGEST len, | |
49 | ULONGEST *xfered_len) override; | |
50 | ||
51 | target_section_table *get_section_table () override; | |
52 | ||
53 | private: | |
891e7584 | 54 | /* The BFD we're wrapping. */ |
f6ac5f3d | 55 | struct bfd *m_bfd; |
891e7584 PA |
56 | |
57 | /* The section table build from the ALLOC sections in BFD. Note | |
58 | that we can't rely on extracting the BFD from a random section in | |
59 | the table, since the table can be legitimately empty. */ | |
f6ac5f3d | 60 | struct target_section_table m_table; |
891e7584 PA |
61 | }; |
62 | ||
f6ac5f3d PA |
63 | target_xfer_status |
64 | target_bfd::xfer_partial (target_object object, | |
65 | const char *annex, gdb_byte *readbuf, | |
66 | const gdb_byte *writebuf, | |
67 | ULONGEST offset, ULONGEST len, | |
68 | ULONGEST *xfered_len) | |
bba2d28d AC |
69 | { |
70 | switch (object) | |
71 | { | |
72 | case TARGET_OBJECT_MEMORY: | |
07b82ea5 | 73 | { |
891e7584 | 74 | return section_table_xfer_memory_partial (readbuf, writebuf, |
9b409511 | 75 | offset, len, xfered_len, |
f6ac5f3d PA |
76 | m_table.sections, |
77 | m_table.sections_end, | |
07b82ea5 PA |
78 | NULL); |
79 | } | |
bba2d28d | 80 | default: |
2ed4b548 | 81 | return TARGET_XFER_E_IO; |
bba2d28d AC |
82 | } |
83 | } | |
84 | ||
f6ac5f3d PA |
85 | target_section_table * |
86 | target_bfd::get_section_table () | |
07b82ea5 | 87 | { |
f6ac5f3d | 88 | return &m_table; |
07b82ea5 PA |
89 | } |
90 | ||
f6ac5f3d | 91 | target_bfd::target_bfd (struct bfd *abfd) |
bba2d28d | 92 | { |
f6ac5f3d PA |
93 | this->to_stratum = file_stratum; |
94 | m_bfd = abfd; | |
95 | gdb_bfd_ref (abfd); | |
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 |
101 | target_bfd::~target_bfd () |
102 | { | |
103 | gdb_bfd_unref (m_bfd); | |
104 | xfree (m_table.sections); | |
bba2d28d AC |
105 | } |
106 | ||
f6ac5f3d | 107 | target_ops * |
ad13d8df | 108 | target_bfd_reopen (struct bfd *abfd) |
bba2d28d | 109 | { |
f6ac5f3d PA |
110 | return new target_bfd (abfd); |
111 | } | |
07b82ea5 | 112 | |
f6ac5f3d PA |
113 | void |
114 | target_bfd::close () | |
115 | { | |
116 | delete this; | |
bba2d28d | 117 | } |