]>
Commit | Line | Data |
---|---|---|
bba2d28d AC |
1 | /* Very simple "bfd" target, for GDB, the GNU debugger. |
2 | ||
7b6bb8da | 3 | Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010, 2011 |
4c38e0a4 | 4 | Free Software Foundation, Inc. |
bba2d28d AC |
5 | |
6 | This file is part of GDB. | |
7 | ||
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
bba2d28d AC |
11 | (at your option) any later version. |
12 | ||
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. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
bba2d28d AC |
20 | |
21 | #include "defs.h" | |
22 | #include "target.h" | |
23 | #include "bfd-target.h" | |
348f8c02 | 24 | #include "exec.h" |
bba2d28d | 25 | |
891e7584 PA |
26 | /* The object that is stored in the target_ops->to_data field has this |
27 | type. */ | |
28 | struct target_bfd_data | |
29 | { | |
30 | /* The BFD we're wrapping. */ | |
31 | struct bfd *bfd; | |
32 | ||
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; | |
37 | }; | |
38 | ||
2c0b251b | 39 | static LONGEST |
bba2d28d AC |
40 | target_bfd_xfer_partial (struct target_ops *ops, |
41 | enum target_object object, | |
961cb7b5 MK |
42 | const char *annex, gdb_byte *readbuf, |
43 | const gdb_byte *writebuf, | |
44 | ULONGEST offset, LONGEST len) | |
bba2d28d AC |
45 | { |
46 | switch (object) | |
47 | { | |
48 | case TARGET_OBJECT_MEMORY: | |
07b82ea5 | 49 | { |
891e7584 PA |
50 | struct target_bfd_data *data = ops->to_data; |
51 | return section_table_xfer_memory_partial (readbuf, writebuf, | |
52 | offset, len, | |
53 | data->table.sections, | |
54 | data->table.sections_end, | |
07b82ea5 PA |
55 | NULL); |
56 | } | |
bba2d28d AC |
57 | default: |
58 | return -1; | |
59 | } | |
60 | } | |
61 | ||
07b82ea5 PA |
62 | static struct target_section_table * |
63 | target_bfd_get_section_table (struct target_ops *ops) | |
64 | { | |
891e7584 PA |
65 | struct target_bfd_data *data = ops->to_data; |
66 | return &data->table; | |
07b82ea5 PA |
67 | } |
68 | ||
2c0b251b | 69 | static void |
bba2d28d AC |
70 | target_bfd_xclose (struct target_ops *t, int quitting) |
71 | { | |
891e7584 PA |
72 | struct target_bfd_data *data = t->to_data; |
73 | ||
74 | bfd_close (data->bfd); | |
75 | xfree (data->table.sections); | |
76 | xfree (data); | |
bba2d28d AC |
77 | xfree (t); |
78 | } | |
79 | ||
80 | struct target_ops * | |
81 | target_bfd_reopen (struct bfd *bfd) | |
82 | { | |
07b82ea5 | 83 | struct target_ops *t; |
891e7584 | 84 | struct target_bfd_data *data; |
07b82ea5 | 85 | |
891e7584 PA |
86 | data = XZALLOC (struct target_bfd_data); |
87 | data->bfd = bfd; | |
88 | build_section_table (bfd, &data->table.sections, &data->table.sections_end); | |
07b82ea5 PA |
89 | |
90 | t = XZALLOC (struct target_ops); | |
bba2d28d | 91 | t->to_shortname = "bfd"; |
3d263c1d BI |
92 | t->to_longname = _("BFD backed target"); |
93 | t->to_doc = _("You should never see this"); | |
07b82ea5 | 94 | t->to_get_section_table = target_bfd_get_section_table; |
bba2d28d AC |
95 | t->to_xfer_partial = target_bfd_xfer_partial; |
96 | t->to_xclose = target_bfd_xclose; | |
891e7584 | 97 | t->to_data = data; |
348f8c02 | 98 | |
bba2d28d AC |
99 | return t; |
100 | } |