GDB (API)
/home/stan/gdb/src/gdb/gdb_bfd.h
Go to the documentation of this file.
00001 /* Definitions for BFD wrappers used by GDB.
00002 
00003    Copyright (C) 2011-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 #ifndef GDB_BFD_H
00021 #define GDB_BFD_H
00022 
00023 #include "registry.h"
00024 
00025 DECLARE_REGISTRY (bfd);
00026 
00027 /* Make a copy ABFD's filename using bfd_alloc, and reassign it to the
00028    BFD.  This ensures that the BFD's filename has the same lifetime as
00029    the BFD itself.  */
00030 
00031 void gdb_bfd_stash_filename (struct bfd *abfd);
00032 
00033 /* Open a read-only (FOPEN_RB) BFD given arguments like bfd_fopen.
00034    Returns NULL on error.  On success, returns a new reference to the
00035    BFD, which must be freed with gdb_bfd_unref.  BFDs returned by this
00036    call are shared among all callers opening the same file.  If FD is
00037    not -1, then after this call it is owned by BFD.  */
00038 
00039 struct bfd *gdb_bfd_open (const char *name, const char *target, int fd);
00040 
00041 /* Increment the reference count of ABFD.  It is fine for ABFD to be
00042    NULL; in this case the function does nothing.  */
00043 
00044 void gdb_bfd_ref (struct bfd *abfd);
00045 
00046 /* Decrement the reference count of ABFD.  If this is the last
00047    reference, ABFD will be freed.  If ABFD is NULL, this function does
00048    nothing.  */
00049 
00050 void gdb_bfd_unref (struct bfd *abfd);
00051 
00052 /* Mark the CHILD BFD as being a member of PARENT.  Also, increment
00053    the reference count of CHILD.  Calling this function ensures that
00054    as along as CHILD remains alive, PARENT will as well.  Both CHILD
00055    and PARENT must be non-NULL.  This can be called more than once
00056    with the same arguments; but it is not allowed to call it for a
00057    single CHILD with different values for PARENT.  */
00058 
00059 void gdb_bfd_mark_parent (bfd *child, bfd *parent);
00060 
00061 /* Try to read or map the contents of the section SECT.  If
00062    successful, the section data is returned and *SIZE is set to the
00063    size of the section data; this may not be the same as the size
00064    according to bfd_get_section_size if the section was compressed.
00065    The returned section data is associated with the BFD and will be
00066    destroyed when the BFD is destroyed.  There is no other way to free
00067    it; for temporary uses of section data, see
00068    bfd_malloc_and_get_section.  SECT may not have relocations.  This
00069    function will throw on error.  */
00070 
00071 const gdb_byte *gdb_bfd_map_section (asection *section, bfd_size_type *size);
00072 
00073 /* Compute the CRC for ABFD.  The CRC is used to find and verify
00074    separate debug files.  When successful, this fills in *CRC_OUT and
00075    returns 1.  Otherwise, this issues a warning and returns 0.  */
00076 
00077 int gdb_bfd_crc (struct bfd *abfd, unsigned long *crc_out);
00078 
00079 
00080 
00081 /* A wrapper for bfd_fopen that initializes the gdb-specific reference
00082    count and calls gdb_bfd_stash_filename.  */
00083 
00084 bfd *gdb_bfd_fopen (const char *, const char *, const char *, int);
00085 
00086 /* A wrapper for bfd_openr that initializes the gdb-specific reference
00087    count and calls gdb_bfd_stash_filename.  */
00088 
00089 bfd *gdb_bfd_openr (const char *, const char *);
00090 
00091 /* A wrapper for bfd_openw that initializes the gdb-specific reference
00092    count and calls gdb_bfd_stash_filename.  */
00093 
00094 bfd *gdb_bfd_openw (const char *, const char *);
00095 
00096 /* A wrapper for bfd_openr_iovec that initializes the gdb-specific
00097    reference count and calls gdb_bfd_stash_filename.  */
00098 
00099 bfd *gdb_bfd_openr_iovec (const char *filename, const char *target,
00100                           void *(*open_func) (struct bfd *nbfd,
00101                                               void *open_closure),
00102                           void *open_closure,
00103                           file_ptr (*pread_func) (struct bfd *nbfd,
00104                                                   void *stream,
00105                                                   void *buf,
00106                                                   file_ptr nbytes,
00107                                                   file_ptr offset),
00108                           int (*close_func) (struct bfd *nbfd,
00109                                              void *stream),
00110                           int (*stat_func) (struct bfd *abfd,
00111                                             void *stream,
00112                                             struct stat *sb));
00113 
00114 /* A wrapper for bfd_openr_next_archived_file that initializes the
00115    gdb-specific reference count and calls gdb_bfd_stash_filename.  */
00116 
00117 bfd *gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous);
00118 
00119 /* A wrapper for bfd_fdopenr that initializes the gdb-specific
00120    reference count and calls gdb_bfd_stash_filename.  */
00121 
00122 bfd *gdb_bfd_fdopenr (const char *filename, const char *target, int fd);
00123 
00124 
00125 
00126 /* Return the index of the BFD section SECTION.  Ordinarily this is
00127    just the section's index, but for some special sections, like
00128    bfd_com_section_ptr, it will be a synthesized value.  */
00129 
00130 int gdb_bfd_section_index (bfd *abfd, asection *section);
00131 
00132 
00133 /* Like bfd_count_sections, but include any possible global sections,
00134    like bfd_com_section_ptr.  */
00135 
00136 int gdb_bfd_count_sections (bfd *abfd);
00137 
00138 /* Return true if any section requires relocations, false
00139    otherwise.  */
00140 
00141 int gdb_bfd_requires_relocations (bfd *abfd);
00142 
00143 #endif /* GDB_BFD_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines