GDB (xrefs)
/tmp/gdb-7.10/gdb/bfd-target.c
Go to the documentation of this file.
1 /* Very simple "bfd" target, for GDB, the GNU debugger.
2 
3  Copyright (C) 2003-2015 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 #include "gdb_bfd.h"
25 
26 /* The object that is stored in the target_ops->to_data field has this
27  type. */
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. */
37 };
38 
39 static enum target_xfer_status
41  enum target_object object,
42  const char *annex, gdb_byte *readbuf,
43  const gdb_byte *writebuf,
45  ULONGEST *xfered_len)
46 {
47  switch (object)
48  {
50  {
51  struct target_bfd_data *data = ops->to_data;
52  return section_table_xfer_memory_partial (readbuf, writebuf,
53  offset, len, xfered_len,
54  data->table.sections,
55  data->table.sections_end,
56  NULL);
57  }
58  default:
59  return TARGET_XFER_E_IO;
60  }
61 }
62 
63 static struct target_section_table *
65 {
66  struct target_bfd_data *data = ops->to_data;
67  return &data->table;
68 }
69 
70 static void
72 {
73  struct target_bfd_data *data = t->to_data;
74 
75  gdb_bfd_unref (data->bfd);
76  xfree (data->table.sections);
77  xfree (data);
78  xfree (t);
79 }
80 
81 struct target_ops *
82 target_bfd_reopen (struct bfd *abfd)
83 {
84  struct target_ops *t;
85  struct target_bfd_data *data;
86 
87  data = XCNEW (struct target_bfd_data);
88  data->bfd = abfd;
89  gdb_bfd_ref (abfd);
90  build_section_table (abfd, &data->table.sections, &data->table.sections_end);
91 
92  t = XCNEW (struct target_ops);
93  t->to_shortname = "bfd";
94  t->to_longname = _("BFD backed target");
95  t->to_doc = _("You should never see this");
99  t->to_data = data;
100  t->to_magic = OPS_MAGIC;
101 
102  return t;
103 }
const char * to_longname
Definition: target.h:433
void xfree(void *)
Definition: common-utils.c:97
struct target_section * sections_end
Definition: target.h:2277
void(* to_xclose)(struct target_ops *targ)
Definition: target.h:447
int build_section_table(struct bfd *some_bfd, struct target_section **start, struct target_section **end)
Definition: exec.c:470
#define _(String)
Definition: gdb_locale.h:40
struct target_section_table table
Definition: bfd-target.c:36
enum target_xfer_status section_table_xfer_memory_partial(gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len, struct target_section *sections, struct target_section *sections_end, const char *section_name)
Definition: exec.c:754
struct bfd * bfd
Definition: bfd-target.c:31
void gdb_bfd_ref(struct bfd *abfd)
Definition: gdb_bfd.c:439
#define OPS_MAGIC
Definition: target.h:1233
void * to_data
Definition: target.h:438
void gdb_bfd_unref(struct bfd *abfd)
Definition: gdb_bfd.c:475
static struct target_section_table * target_bfd_get_section_table(struct target_ops *ops)
Definition: bfd-target.c:64
struct target_ops * target_bfd_reopen(struct bfd *abfd)
Definition: bfd-target.c:82
struct target_section_table *(* to_get_section_table)(struct target_ops *) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:648
struct target_section * sections
Definition: target.h:2276
target_xfer_status
Definition: target.h:219
static void target_bfd_xclose(struct target_ops *t)
Definition: bfd-target.c:71
const char * to_doc
Definition: target.h:434
enum target_xfer_status(* to_xfer_partial)(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
Definition: target.h:724
target_object
Definition: target.h:136
static enum target_xfer_status target_bfd_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
Definition: bfd-target.c:40
bfd_byte gdb_byte
Definition: common-types.h:38
int offset
Definition: agent.c:65
const char * to_shortname
Definition: target.h:432
unsigned long long ULONGEST
Definition: common-types.h:53
int to_magic
Definition: target.h:1224
const ULONGEST const LONGEST len
Definition: target.h:309