GDB (API)
|
00001 /* Very simple "bfd" target, for GDB, the GNU debugger. 00002 00003 Copyright (C) 2003-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "target.h" 00022 #include "bfd-target.h" 00023 #include "exec.h" 00024 #include "gdb_bfd.h" 00025 00026 /* The object that is stored in the target_ops->to_data field has this 00027 type. */ 00028 struct target_bfd_data 00029 { 00030 /* The BFD we're wrapping. */ 00031 struct bfd *bfd; 00032 00033 /* The section table build from the ALLOC sections in BFD. Note 00034 that we can't rely on extracting the BFD from a random section in 00035 the table, since the table can be legitimately empty. */ 00036 struct target_section_table table; 00037 }; 00038 00039 static LONGEST 00040 target_bfd_xfer_partial (struct target_ops *ops, 00041 enum target_object object, 00042 const char *annex, gdb_byte *readbuf, 00043 const gdb_byte *writebuf, 00044 ULONGEST offset, LONGEST len) 00045 { 00046 switch (object) 00047 { 00048 case TARGET_OBJECT_MEMORY: 00049 { 00050 struct target_bfd_data *data = ops->to_data; 00051 return section_table_xfer_memory_partial (readbuf, writebuf, 00052 offset, len, 00053 data->table.sections, 00054 data->table.sections_end, 00055 NULL); 00056 } 00057 default: 00058 return -1; 00059 } 00060 } 00061 00062 static struct target_section_table * 00063 target_bfd_get_section_table (struct target_ops *ops) 00064 { 00065 struct target_bfd_data *data = ops->to_data; 00066 return &data->table; 00067 } 00068 00069 static void 00070 target_bfd_xclose (struct target_ops *t) 00071 { 00072 struct target_bfd_data *data = t->to_data; 00073 00074 gdb_bfd_unref (data->bfd); 00075 xfree (data->table.sections); 00076 xfree (data); 00077 xfree (t); 00078 } 00079 00080 struct target_ops * 00081 target_bfd_reopen (struct bfd *abfd) 00082 { 00083 struct target_ops *t; 00084 struct target_bfd_data *data; 00085 00086 data = XZALLOC (struct target_bfd_data); 00087 data->bfd = abfd; 00088 gdb_bfd_ref (abfd); 00089 build_section_table (abfd, &data->table.sections, &data->table.sections_end); 00090 00091 t = XZALLOC (struct target_ops); 00092 t->to_shortname = "bfd"; 00093 t->to_longname = _("BFD backed target"); 00094 t->to_doc = _("You should never see this"); 00095 t->to_get_section_table = target_bfd_get_section_table; 00096 t->to_xfer_partial = target_bfd_xfer_partial; 00097 t->to_xclose = target_bfd_xclose; 00098 t->to_data = data; 00099 t->to_magic = OPS_MAGIC; 00100 00101 return t; 00102 }