1*5796c8dcSSimon Schubert /* Very simple "bfd" target, for GDB, the GNU debugger. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 2003, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. 4*5796c8dcSSimon Schubert 5*5796c8dcSSimon Schubert This file is part of GDB. 6*5796c8dcSSimon Schubert 7*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 8*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 9*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 10*5796c8dcSSimon Schubert (at your option) any later version. 11*5796c8dcSSimon Schubert 12*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 13*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 14*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*5796c8dcSSimon Schubert GNU General Public License for more details. 16*5796c8dcSSimon Schubert 17*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 18*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*5796c8dcSSimon Schubert 20*5796c8dcSSimon Schubert #include "defs.h" 21*5796c8dcSSimon Schubert #include "target.h" 22*5796c8dcSSimon Schubert #include "bfd-target.h" 23*5796c8dcSSimon Schubert #include "exec.h" 24*5796c8dcSSimon Schubert 25*5796c8dcSSimon Schubert /* The object that is stored in the target_ops->to_data field has this 26*5796c8dcSSimon Schubert type. */ 27*5796c8dcSSimon Schubert struct target_bfd_data 28*5796c8dcSSimon Schubert { 29*5796c8dcSSimon Schubert /* The BFD we're wrapping. */ 30*5796c8dcSSimon Schubert struct bfd *bfd; 31*5796c8dcSSimon Schubert 32*5796c8dcSSimon Schubert /* The section table build from the ALLOC sections in BFD. Note 33*5796c8dcSSimon Schubert that we can't rely on extracting the BFD from a random section in 34*5796c8dcSSimon Schubert the table, since the table can be legitimately empty. */ 35*5796c8dcSSimon Schubert struct target_section_table table; 36*5796c8dcSSimon Schubert }; 37*5796c8dcSSimon Schubert 38*5796c8dcSSimon Schubert static LONGEST 39*5796c8dcSSimon Schubert target_bfd_xfer_partial (struct target_ops *ops, 40*5796c8dcSSimon Schubert enum target_object object, 41*5796c8dcSSimon Schubert const char *annex, gdb_byte *readbuf, 42*5796c8dcSSimon Schubert const gdb_byte *writebuf, 43*5796c8dcSSimon Schubert ULONGEST offset, LONGEST len) 44*5796c8dcSSimon Schubert { 45*5796c8dcSSimon Schubert switch (object) 46*5796c8dcSSimon Schubert { 47*5796c8dcSSimon Schubert case TARGET_OBJECT_MEMORY: 48*5796c8dcSSimon Schubert { 49*5796c8dcSSimon Schubert struct target_bfd_data *data = ops->to_data; 50*5796c8dcSSimon Schubert return section_table_xfer_memory_partial (readbuf, writebuf, 51*5796c8dcSSimon Schubert offset, len, 52*5796c8dcSSimon Schubert data->table.sections, 53*5796c8dcSSimon Schubert data->table.sections_end, 54*5796c8dcSSimon Schubert NULL); 55*5796c8dcSSimon Schubert } 56*5796c8dcSSimon Schubert default: 57*5796c8dcSSimon Schubert return -1; 58*5796c8dcSSimon Schubert } 59*5796c8dcSSimon Schubert } 60*5796c8dcSSimon Schubert 61*5796c8dcSSimon Schubert static struct target_section_table * 62*5796c8dcSSimon Schubert target_bfd_get_section_table (struct target_ops *ops) 63*5796c8dcSSimon Schubert { 64*5796c8dcSSimon Schubert struct target_bfd_data *data = ops->to_data; 65*5796c8dcSSimon Schubert return &data->table; 66*5796c8dcSSimon Schubert } 67*5796c8dcSSimon Schubert 68*5796c8dcSSimon Schubert static void 69*5796c8dcSSimon Schubert target_bfd_xclose (struct target_ops *t, int quitting) 70*5796c8dcSSimon Schubert { 71*5796c8dcSSimon Schubert struct target_bfd_data *data = t->to_data; 72*5796c8dcSSimon Schubert 73*5796c8dcSSimon Schubert bfd_close (data->bfd); 74*5796c8dcSSimon Schubert xfree (data->table.sections); 75*5796c8dcSSimon Schubert xfree (data); 76*5796c8dcSSimon Schubert xfree (t); 77*5796c8dcSSimon Schubert } 78*5796c8dcSSimon Schubert 79*5796c8dcSSimon Schubert struct target_ops * 80*5796c8dcSSimon Schubert target_bfd_reopen (struct bfd *bfd) 81*5796c8dcSSimon Schubert { 82*5796c8dcSSimon Schubert struct target_ops *t; 83*5796c8dcSSimon Schubert struct target_bfd_data *data; 84*5796c8dcSSimon Schubert 85*5796c8dcSSimon Schubert data = XZALLOC (struct target_bfd_data); 86*5796c8dcSSimon Schubert data->bfd = bfd; 87*5796c8dcSSimon Schubert build_section_table (bfd, &data->table.sections, &data->table.sections_end); 88*5796c8dcSSimon Schubert 89*5796c8dcSSimon Schubert t = XZALLOC (struct target_ops); 90*5796c8dcSSimon Schubert t->to_shortname = "bfd"; 91*5796c8dcSSimon Schubert t->to_longname = _("BFD backed target"); 92*5796c8dcSSimon Schubert t->to_doc = _("You should never see this"); 93*5796c8dcSSimon Schubert t->to_get_section_table = target_bfd_get_section_table; 94*5796c8dcSSimon Schubert t->to_xfer_partial = target_bfd_xfer_partial; 95*5796c8dcSSimon Schubert t->to_xclose = target_bfd_xclose; 96*5796c8dcSSimon Schubert t->to_data = data; 97*5796c8dcSSimon Schubert 98*5796c8dcSSimon Schubert return t; 99*5796c8dcSSimon Schubert } 100