xref: /dflybsd-src/contrib/gdb-7/gdb/bfd-target.c (revision a45ae5f869d9cfcb3e41dbab486e10bfa9e336bf)
15796c8dcSSimon Schubert /* Very simple "bfd" target, for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
3*a45ae5f8SJohn Marino    Copyright (C) 2003, 2005, 2007-2012 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "target.h"
225796c8dcSSimon Schubert #include "bfd-target.h"
235796c8dcSSimon Schubert #include "exec.h"
245796c8dcSSimon Schubert 
255796c8dcSSimon Schubert /* The object that is stored in the target_ops->to_data field has this
265796c8dcSSimon Schubert    type.  */
275796c8dcSSimon Schubert struct target_bfd_data
285796c8dcSSimon Schubert {
295796c8dcSSimon Schubert   /* The BFD we're wrapping.  */
305796c8dcSSimon Schubert   struct bfd *bfd;
315796c8dcSSimon Schubert 
325796c8dcSSimon Schubert   /* The section table build from the ALLOC sections in BFD.  Note
335796c8dcSSimon Schubert      that we can't rely on extracting the BFD from a random section in
345796c8dcSSimon Schubert      the table, since the table can be legitimately empty.  */
355796c8dcSSimon Schubert   struct target_section_table table;
365796c8dcSSimon Schubert };
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert static LONGEST
395796c8dcSSimon Schubert target_bfd_xfer_partial (struct target_ops *ops,
405796c8dcSSimon Schubert 			 enum target_object object,
415796c8dcSSimon Schubert 			 const char *annex, gdb_byte *readbuf,
425796c8dcSSimon Schubert 			 const gdb_byte *writebuf,
435796c8dcSSimon Schubert 			 ULONGEST offset, LONGEST len)
445796c8dcSSimon Schubert {
455796c8dcSSimon Schubert   switch (object)
465796c8dcSSimon Schubert     {
475796c8dcSSimon Schubert     case TARGET_OBJECT_MEMORY:
485796c8dcSSimon Schubert       {
495796c8dcSSimon Schubert 	struct target_bfd_data *data = ops->to_data;
505796c8dcSSimon Schubert 	return section_table_xfer_memory_partial (readbuf, writebuf,
515796c8dcSSimon Schubert 						  offset, len,
525796c8dcSSimon Schubert 						  data->table.sections,
535796c8dcSSimon Schubert 						  data->table.sections_end,
545796c8dcSSimon Schubert 						  NULL);
555796c8dcSSimon Schubert       }
565796c8dcSSimon Schubert     default:
575796c8dcSSimon Schubert       return -1;
585796c8dcSSimon Schubert     }
595796c8dcSSimon Schubert }
605796c8dcSSimon Schubert 
615796c8dcSSimon Schubert static struct target_section_table *
625796c8dcSSimon Schubert target_bfd_get_section_table (struct target_ops *ops)
635796c8dcSSimon Schubert {
645796c8dcSSimon Schubert   struct target_bfd_data *data = ops->to_data;
655796c8dcSSimon Schubert   return &data->table;
665796c8dcSSimon Schubert }
675796c8dcSSimon Schubert 
685796c8dcSSimon Schubert static void
695796c8dcSSimon Schubert target_bfd_xclose (struct target_ops *t, int quitting)
705796c8dcSSimon Schubert {
715796c8dcSSimon Schubert   struct target_bfd_data *data = t->to_data;
725796c8dcSSimon Schubert 
735796c8dcSSimon Schubert   bfd_close (data->bfd);
745796c8dcSSimon Schubert   xfree (data->table.sections);
755796c8dcSSimon Schubert   xfree (data);
765796c8dcSSimon Schubert   xfree (t);
775796c8dcSSimon Schubert }
785796c8dcSSimon Schubert 
795796c8dcSSimon Schubert struct target_ops *
80*a45ae5f8SJohn Marino target_bfd_reopen (struct bfd *abfd)
815796c8dcSSimon Schubert {
825796c8dcSSimon Schubert   struct target_ops *t;
835796c8dcSSimon Schubert   struct target_bfd_data *data;
845796c8dcSSimon Schubert 
855796c8dcSSimon Schubert   data = XZALLOC (struct target_bfd_data);
86*a45ae5f8SJohn Marino   data->bfd = abfd;
87*a45ae5f8SJohn Marino   build_section_table (abfd, &data->table.sections, &data->table.sections_end);
885796c8dcSSimon Schubert 
895796c8dcSSimon Schubert   t = XZALLOC (struct target_ops);
905796c8dcSSimon Schubert   t->to_shortname = "bfd";
915796c8dcSSimon Schubert   t->to_longname = _("BFD backed target");
925796c8dcSSimon Schubert   t->to_doc = _("You should never see this");
935796c8dcSSimon Schubert   t->to_get_section_table = target_bfd_get_section_table;
945796c8dcSSimon Schubert   t->to_xfer_partial = target_bfd_xfer_partial;
955796c8dcSSimon Schubert   t->to_xclose = target_bfd_xclose;
965796c8dcSSimon Schubert   t->to_data = data;
975796c8dcSSimon Schubert 
985796c8dcSSimon Schubert   return t;
995796c8dcSSimon Schubert }
100