1 /* Very simple "bfd" target, for GDB, the GNU debugger.
3 Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #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;
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, LONGEST len)
48 case TARGET_OBJECT_MEMORY:
50 struct target_bfd_data *data = ops->to_data;
51 return section_table_xfer_memory_partial (readbuf, writebuf,
54 data->table.sections_end,
62 static struct target_section_table *
63 target_bfd_get_section_table (struct target_ops *ops)
65 struct target_bfd_data *data = ops->to_data;
70 target_bfd_xclose (struct target_ops *t, int quitting)
72 struct target_bfd_data *data = t->to_data;
74 bfd_close (data->bfd);
75 xfree (data->table.sections);
81 target_bfd_reopen (struct bfd *bfd)
84 struct target_bfd_data *data;
86 data = XZALLOC (struct target_bfd_data);
88 build_section_table (bfd, &data->table.sections, &data->table.sections_end);
90 t = XZALLOC (struct target_ops);
91 t->to_shortname = "bfd";
92 t->to_longname = _("BFD backed target");
93 t->to_doc = _("You should never see this");
94 t->to_get_section_table = target_bfd_get_section_table;
95 t->to_xfer_partial = target_bfd_xfer_partial;
96 t->to_xclose = target_bfd_xclose;