1 /* Very simple "bfd" target, for GDB, the GNU debugger.
3 Copyright (C) 2003-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
22 #include "bfd-target.h"
26 /* The object that is stored in the target_ops->to_data field has this
28 struct target_bfd_data
30 /* The BFD we're wrapping. */
33 /* The section table build from the ALLOC sections in BFD. Note
34 that we can't rely on extracting the BFD from a random section in
35 the table, since the table can be legitimately empty. */
36 struct target_section_table table;
39 static enum target_xfer_status
40 target_bfd_xfer_partial (struct target_ops *ops,
41 enum target_object object,
42 const char *annex, gdb_byte *readbuf,
43 const gdb_byte *writebuf,
44 ULONGEST offset, ULONGEST len,
49 case TARGET_OBJECT_MEMORY:
51 struct target_bfd_data *data = (struct target_bfd_data *) ops->to_data;
52 return section_table_xfer_memory_partial (readbuf, writebuf,
53 offset, len, xfered_len,
55 data->table.sections_end,
59 return TARGET_XFER_E_IO;
63 static struct target_section_table *
64 target_bfd_get_section_table (struct target_ops *ops)
66 struct target_bfd_data *data = (struct target_bfd_data *) ops->to_data;
71 target_bfd_xclose (struct target_ops *t)
73 struct target_bfd_data *data = (struct target_bfd_data *) t->to_data;
75 gdb_bfd_unref (data->bfd);
76 xfree (data->table.sections);
82 target_bfd_reopen (struct bfd *abfd)
85 struct target_bfd_data *data;
87 data = XCNEW (struct target_bfd_data);
90 build_section_table (abfd, &data->table.sections, &data->table.sections_end);
92 t = XCNEW (struct target_ops);
93 t->to_shortname = "bfd";
94 t->to_longname = _("BFD backed target");
95 t->to_doc = _("You should never see this");
96 t->to_get_section_table = target_bfd_get_section_table;
97 t->to_xfer_partial = target_bfd_xfer_partial;
98 t->to_xclose = target_bfd_xclose;
100 t->to_magic = OPS_MAGIC;