2012-03-08 Luis Machado <lgustavo@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / bfd-target.c
1 /* Very simple "bfd" target, for GDB, the GNU debugger.
2
3 Copyright (C) 2003, 2005, 2007-2012 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 #include "target.h"
22 #include "bfd-target.h"
23 #include "exec.h"
24
25 /* The object that is stored in the target_ops->to_data field has this
26 type. */
27 struct target_bfd_data
28 {
29 /* The BFD we're wrapping. */
30 struct bfd *bfd;
31
32 /* The section table build from the ALLOC sections in BFD. Note
33 that we can't rely on extracting the BFD from a random section in
34 the table, since the table can be legitimately empty. */
35 struct target_section_table table;
36 };
37
38 static LONGEST
39 target_bfd_xfer_partial (struct target_ops *ops,
40 enum target_object object,
41 const char *annex, gdb_byte *readbuf,
42 const gdb_byte *writebuf,
43 ULONGEST offset, LONGEST len)
44 {
45 switch (object)
46 {
47 case TARGET_OBJECT_MEMORY:
48 {
49 struct target_bfd_data *data = ops->to_data;
50 return section_table_xfer_memory_partial (readbuf, writebuf,
51 offset, len,
52 data->table.sections,
53 data->table.sections_end,
54 NULL);
55 }
56 default:
57 return -1;
58 }
59 }
60
61 static struct target_section_table *
62 target_bfd_get_section_table (struct target_ops *ops)
63 {
64 struct target_bfd_data *data = ops->to_data;
65 return &data->table;
66 }
67
68 static void
69 target_bfd_xclose (struct target_ops *t, int quitting)
70 {
71 struct target_bfd_data *data = t->to_data;
72
73 bfd_close (data->bfd);
74 xfree (data->table.sections);
75 xfree (data);
76 xfree (t);
77 }
78
79 struct target_ops *
80 target_bfd_reopen (struct bfd *abfd)
81 {
82 struct target_ops *t;
83 struct target_bfd_data *data;
84
85 data = XZALLOC (struct target_bfd_data);
86 data->bfd = abfd;
87 build_section_table (abfd, &data->table.sections, &data->table.sections_end);
88
89 t = XZALLOC (struct target_ops);
90 t->to_shortname = "bfd";
91 t->to_longname = _("BFD backed target");
92 t->to_doc = _("You should never see this");
93 t->to_get_section_table = target_bfd_get_section_table;
94 t->to_xfer_partial = target_bfd_xfer_partial;
95 t->to_xclose = target_bfd_xclose;
96 t->to_data = data;
97
98 return t;
99 }
This page took 0.03238 seconds and 4 git commands to generate.