xref: /dflybsd-src/contrib/gdb-7/gdb/gdb_bfd.h (revision de8e141f24382815c10a4012d209bbbf7abf1112)
1*ef5ccd6cSJohn Marino /* Definitions for BFD wrappers used by GDB.
2*ef5ccd6cSJohn Marino 
3*ef5ccd6cSJohn Marino    Copyright (C) 2011-2013 Free Software Foundation, Inc.
4*ef5ccd6cSJohn Marino 
5*ef5ccd6cSJohn Marino    This file is part of GDB.
6*ef5ccd6cSJohn Marino 
7*ef5ccd6cSJohn Marino    This program is free software; you can redistribute it and/or modify
8*ef5ccd6cSJohn Marino    it under the terms of the GNU General Public License as published by
9*ef5ccd6cSJohn Marino    the Free Software Foundation; either version 3 of the License, or
10*ef5ccd6cSJohn Marino    (at your option) any later version.
11*ef5ccd6cSJohn Marino 
12*ef5ccd6cSJohn Marino    This program is distributed in the hope that it will be useful,
13*ef5ccd6cSJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*ef5ccd6cSJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*ef5ccd6cSJohn Marino    GNU General Public License for more details.
16*ef5ccd6cSJohn Marino 
17*ef5ccd6cSJohn Marino    You should have received a copy of the GNU General Public License
18*ef5ccd6cSJohn Marino    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*ef5ccd6cSJohn Marino 
20*ef5ccd6cSJohn Marino #ifndef GDB_BFD_H
21*ef5ccd6cSJohn Marino #define GDB_BFD_H
22*ef5ccd6cSJohn Marino 
23*ef5ccd6cSJohn Marino #include "registry.h"
24*ef5ccd6cSJohn Marino 
25*ef5ccd6cSJohn Marino DECLARE_REGISTRY (bfd);
26*ef5ccd6cSJohn Marino 
27*ef5ccd6cSJohn Marino /* Make a copy ABFD's filename using bfd_alloc, and reassign it to the
28*ef5ccd6cSJohn Marino    BFD.  This ensures that the BFD's filename has the same lifetime as
29*ef5ccd6cSJohn Marino    the BFD itself.  */
30*ef5ccd6cSJohn Marino 
31*ef5ccd6cSJohn Marino void gdb_bfd_stash_filename (struct bfd *abfd);
32*ef5ccd6cSJohn Marino 
33*ef5ccd6cSJohn Marino /* Open a read-only (FOPEN_RB) BFD given arguments like bfd_fopen.
34*ef5ccd6cSJohn Marino    Returns NULL on error.  On success, returns a new reference to the
35*ef5ccd6cSJohn Marino    BFD, which must be freed with gdb_bfd_unref.  BFDs returned by this
36*ef5ccd6cSJohn Marino    call are shared among all callers opening the same file.  If FD is
37*ef5ccd6cSJohn Marino    not -1, then after this call it is owned by BFD.  */
38*ef5ccd6cSJohn Marino 
39*ef5ccd6cSJohn Marino struct bfd *gdb_bfd_open (const char *name, const char *target, int fd);
40*ef5ccd6cSJohn Marino 
41*ef5ccd6cSJohn Marino /* Increment the reference count of ABFD.  It is fine for ABFD to be
42*ef5ccd6cSJohn Marino    NULL; in this case the function does nothing.  */
43*ef5ccd6cSJohn Marino 
44*ef5ccd6cSJohn Marino void gdb_bfd_ref (struct bfd *abfd);
45*ef5ccd6cSJohn Marino 
46*ef5ccd6cSJohn Marino /* Decrement the reference count of ABFD.  If this is the last
47*ef5ccd6cSJohn Marino    reference, ABFD will be freed.  If ABFD is NULL, this function does
48*ef5ccd6cSJohn Marino    nothing.  */
49*ef5ccd6cSJohn Marino 
50*ef5ccd6cSJohn Marino void gdb_bfd_unref (struct bfd *abfd);
51*ef5ccd6cSJohn Marino 
52*ef5ccd6cSJohn Marino /* Mark the CHILD BFD as being a member of PARENT.  Also, increment
53*ef5ccd6cSJohn Marino    the reference count of CHILD.  Calling this function ensures that
54*ef5ccd6cSJohn Marino    as along as CHILD remains alive, PARENT will as well.  Both CHILD
55*ef5ccd6cSJohn Marino    and PARENT must be non-NULL.  This can be called more than once
56*ef5ccd6cSJohn Marino    with the same arguments; but it is not allowed to call it for a
57*ef5ccd6cSJohn Marino    single CHILD with different values for PARENT.  */
58*ef5ccd6cSJohn Marino 
59*ef5ccd6cSJohn Marino void gdb_bfd_mark_parent (bfd *child, bfd *parent);
60*ef5ccd6cSJohn Marino 
61*ef5ccd6cSJohn Marino /* Try to read or map the contents of the section SECT.  If
62*ef5ccd6cSJohn Marino    successful, the section data is returned and *SIZE is set to the
63*ef5ccd6cSJohn Marino    size of the section data; this may not be the same as the size
64*ef5ccd6cSJohn Marino    according to bfd_get_section_size if the section was compressed.
65*ef5ccd6cSJohn Marino    The returned section data is associated with the BFD and will be
66*ef5ccd6cSJohn Marino    destroyed when the BFD is destroyed.  There is no other way to free
67*ef5ccd6cSJohn Marino    it; for temporary uses of section data, see
68*ef5ccd6cSJohn Marino    bfd_malloc_and_get_section.  SECT may not have relocations.  This
69*ef5ccd6cSJohn Marino    function will throw on error.  */
70*ef5ccd6cSJohn Marino 
71*ef5ccd6cSJohn Marino const gdb_byte *gdb_bfd_map_section (asection *section, bfd_size_type *size);
72*ef5ccd6cSJohn Marino 
73*ef5ccd6cSJohn Marino 
74*ef5ccd6cSJohn Marino 
75*ef5ccd6cSJohn Marino /* A wrapper for bfd_fopen that initializes the gdb-specific reference
76*ef5ccd6cSJohn Marino    count and calls gdb_bfd_stash_filename.  */
77*ef5ccd6cSJohn Marino 
78*ef5ccd6cSJohn Marino bfd *gdb_bfd_fopen (const char *, const char *, const char *, int);
79*ef5ccd6cSJohn Marino 
80*ef5ccd6cSJohn Marino /* A wrapper for bfd_openr that initializes the gdb-specific reference
81*ef5ccd6cSJohn Marino    count and calls gdb_bfd_stash_filename.  */
82*ef5ccd6cSJohn Marino 
83*ef5ccd6cSJohn Marino bfd *gdb_bfd_openr (const char *, const char *);
84*ef5ccd6cSJohn Marino 
85*ef5ccd6cSJohn Marino /* A wrapper for bfd_openw that initializes the gdb-specific reference
86*ef5ccd6cSJohn Marino    count and calls gdb_bfd_stash_filename.  */
87*ef5ccd6cSJohn Marino 
88*ef5ccd6cSJohn Marino bfd *gdb_bfd_openw (const char *, const char *);
89*ef5ccd6cSJohn Marino 
90*ef5ccd6cSJohn Marino /* A wrapper for bfd_openr_iovec that initializes the gdb-specific
91*ef5ccd6cSJohn Marino    reference count and calls gdb_bfd_stash_filename.  */
92*ef5ccd6cSJohn Marino 
93*ef5ccd6cSJohn Marino bfd *gdb_bfd_openr_iovec (const char *filename, const char *target,
94*ef5ccd6cSJohn Marino 			  void *(*open_func) (struct bfd *nbfd,
95*ef5ccd6cSJohn Marino 					      void *open_closure),
96*ef5ccd6cSJohn Marino 			  void *open_closure,
97*ef5ccd6cSJohn Marino 			  file_ptr (*pread_func) (struct bfd *nbfd,
98*ef5ccd6cSJohn Marino 						  void *stream,
99*ef5ccd6cSJohn Marino 						  void *buf,
100*ef5ccd6cSJohn Marino 						  file_ptr nbytes,
101*ef5ccd6cSJohn Marino 						  file_ptr offset),
102*ef5ccd6cSJohn Marino 			  int (*close_func) (struct bfd *nbfd,
103*ef5ccd6cSJohn Marino 					     void *stream),
104*ef5ccd6cSJohn Marino 			  int (*stat_func) (struct bfd *abfd,
105*ef5ccd6cSJohn Marino 					    void *stream,
106*ef5ccd6cSJohn Marino 					    struct stat *sb));
107*ef5ccd6cSJohn Marino 
108*ef5ccd6cSJohn Marino /* A wrapper for bfd_openr_next_archived_file that initializes the
109*ef5ccd6cSJohn Marino    gdb-specific reference count and calls gdb_bfd_stash_filename.  */
110*ef5ccd6cSJohn Marino 
111*ef5ccd6cSJohn Marino bfd *gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous);
112*ef5ccd6cSJohn Marino 
113*ef5ccd6cSJohn Marino /* A wrapper for bfd_fdopenr that initializes the gdb-specific
114*ef5ccd6cSJohn Marino    reference count and calls gdb_bfd_stash_filename.  */
115*ef5ccd6cSJohn Marino 
116*ef5ccd6cSJohn Marino bfd *gdb_bfd_fdopenr (const char *filename, const char *target, int fd);
117*ef5ccd6cSJohn Marino 
118*ef5ccd6cSJohn Marino #endif /* GDB_BFD_H */
119