1@section Opening and closing BFDs 2 3 4@findex bfd_openr 5@subsubsection @code{bfd_openr} 6@strong{Synopsis} 7@example 8bfd *bfd_openr (const char *filename, const char *target); 9@end example 10@strong{Description}@* 11Open the file @var{filename} (using @code{fopen}) with the target 12@var{target}. Return a pointer to the created BFD. 13 14Calls @code{bfd_find_target}, so @var{target} is interpreted as by 15that function. 16 17If @code{NULL} is returned then an error has occured. Possible errors 18are @code{bfd_error_no_memory}, @code{bfd_error_invalid_target} or 19@code{system_call} error. 20 21@findex bfd_fdopenr 22@subsubsection @code{bfd_fdopenr} 23@strong{Synopsis} 24@example 25bfd *bfd_fdopenr (const char *filename, const char *target, int fd); 26@end example 27@strong{Description}@* 28@code{bfd_fdopenr} is to @code{bfd_fopenr} much like @code{fdopen} is to 29@code{fopen}. It opens a BFD on a file already described by the 30@var{fd} supplied. 31 32When the file is later @code{bfd_close}d, the file descriptor will 33be closed. If the caller desires that this file descriptor be 34cached by BFD (opened as needed, closed as needed to free 35descriptors for other opens), with the supplied @var{fd} used as 36an initial file descriptor (but subject to closure at any time), 37call bfd_set_cacheable(bfd, 1) on the returned BFD. The default 38is to assume no caching; the file descriptor will remain open 39until @code{bfd_close}, and will not be affected by BFD operations 40on other files. 41 42Possible errors are @code{bfd_error_no_memory}, 43@code{bfd_error_invalid_target} and @code{bfd_error_system_call}. 44 45@findex bfd_openstreamr 46@subsubsection @code{bfd_openstreamr} 47@strong{Synopsis} 48@example 49bfd *bfd_openstreamr (const char *, const char *, void *); 50@end example 51@strong{Description}@* 52Open a BFD for read access on an existing stdio stream. When 53the BFD is passed to @code{bfd_close}, the stream will be closed. 54 55@findex bfd_openw 56@subsubsection @code{bfd_openw} 57@strong{Synopsis} 58@example 59bfd *bfd_openw (const char *filename, const char *target); 60@end example 61@strong{Description}@* 62Create a BFD, associated with file @var{filename}, using the 63file format @var{target}, and return a pointer to it. 64 65Possible errors are @code{bfd_error_system_call}, @code{bfd_error_no_memory}, 66@code{bfd_error_invalid_target}. 67 68@findex bfd_close 69@subsubsection @code{bfd_close} 70@strong{Synopsis} 71@example 72bfd_boolean bfd_close (bfd *abfd); 73@end example 74@strong{Description}@* 75Close a BFD. If the BFD was open for writing, then pending 76operations are completed and the file written out and closed. 77If the created file is executable, then @code{chmod} is called 78to mark it as such. 79 80All memory attached to the BFD is released. 81 82The file descriptor associated with the BFD is closed (even 83if it was passed in to BFD by @code{bfd_fdopenr}). 84 85@strong{Returns}@* 86@code{TRUE} is returned if all is ok, otherwise @code{FALSE}. 87 88@findex bfd_close_all_done 89@subsubsection @code{bfd_close_all_done} 90@strong{Synopsis} 91@example 92bfd_boolean bfd_close_all_done (bfd *); 93@end example 94@strong{Description}@* 95Close a BFD. Differs from @code{bfd_close} since it does not 96complete any pending operations. This routine would be used 97if the application had just used BFD for swapping and didn't 98want to use any of the writing code. 99 100If the created file is executable, then @code{chmod} is called 101to mark it as such. 102 103All memory attached to the BFD is released. 104 105@strong{Returns}@* 106@code{TRUE} is returned if all is ok, otherwise @code{FALSE}. 107 108@findex bfd_create 109@subsubsection @code{bfd_create} 110@strong{Synopsis} 111@example 112bfd *bfd_create (const char *filename, bfd *templ); 113@end example 114@strong{Description}@* 115Create a new BFD in the manner of @code{bfd_openw}, but without 116opening a file. The new BFD takes the target from the target 117used by @var{template}. The format is always set to @code{bfd_object}. 118 119@findex bfd_make_writable 120@subsubsection @code{bfd_make_writable} 121@strong{Synopsis} 122@example 123bfd_boolean bfd_make_writable (bfd *abfd); 124@end example 125@strong{Description}@* 126Takes a BFD as created by @code{bfd_create} and converts it 127into one like as returned by @code{bfd_openw}. It does this 128by converting the BFD to BFD_IN_MEMORY. It's assumed that 129you will call @code{bfd_make_readable} on this bfd later. 130 131@strong{Returns}@* 132@code{TRUE} is returned if all is ok, otherwise @code{FALSE}. 133 134@findex bfd_make_readable 135@subsubsection @code{bfd_make_readable} 136@strong{Synopsis} 137@example 138bfd_boolean bfd_make_readable (bfd *abfd); 139@end example 140@strong{Description}@* 141Takes a BFD as created by @code{bfd_create} and 142@code{bfd_make_writable} and converts it into one like as 143returned by @code{bfd_openr}. It does this by writing the 144contents out to the memory buffer, then reversing the 145direction. 146 147@strong{Returns}@* 148@code{TRUE} is returned if all is ok, otherwise @code{FALSE}. 149 150@findex bfd_alloc 151@subsubsection @code{bfd_alloc} 152@strong{Synopsis} 153@example 154void *bfd_alloc (bfd *abfd, size_t wanted); 155@end example 156@strong{Description}@* 157Allocate a block of @var{wanted} bytes of memory attached to 158@code{abfd} and return a pointer to it. 159 160@findex bfd_calc_gnu_debuglink_crc32 161@subsubsection @code{bfd_calc_gnu_debuglink_crc32} 162@strong{Synopsis} 163@example 164unsigned long bfd_calc_gnu_debuglink_crc32 165 (unsigned long crc, const unsigned char *buf, bfd_size_type len); 166@end example 167@strong{Description}@* 168Computes a CRC value as used in the .gnu_debuglink section. 169Advances the previously computed @var{crc} value by computing 170and adding in the crc32 for @var{len} bytes of @var{buf}. 171 172@strong{Returns}@* 173Return the updated CRC32 value. 174 175@findex get_debug_link_info 176@subsubsection @code{get_debug_link_info} 177@strong{Synopsis} 178@example 179char *get_debug_link_info (bfd *abfd, unsigned long *crc32_out); 180@end example 181@strong{Description}@* 182fetch the filename and CRC32 value for any separate debuginfo 183associated with @var{abfd}. Return NULL if no such info found, 184otherwise return filename and update @var{crc32_out}. 185 186@findex separate_debug_file_exists 187@subsubsection @code{separate_debug_file_exists} 188@strong{Synopsis} 189@example 190bfd_boolean separate_debug_file_exists 191 (char *name, unsigned long crc32); 192@end example 193@strong{Description}@* 194Checks to see if @var{name} is a file and if its contents 195match @var{crc32}. 196 197@findex find_separate_debug_file 198@subsubsection @code{find_separate_debug_file} 199@strong{Synopsis} 200@example 201char *find_separate_debug_file (bfd *abfd); 202@end example 203@strong{Description}@* 204Searches @var{abfd} for a reference to separate debugging 205information, scans various locations in the filesystem, including 206the file tree rooted at @var{debug_file_directory}, and returns a 207filename of such debugging information if the file is found and has 208matching CRC32. Returns NULL if no reference to debugging file 209exists, or file cannot be found. 210 211@findex bfd_follow_gnu_debuglink 212@subsubsection @code{bfd_follow_gnu_debuglink} 213@strong{Synopsis} 214@example 215char *bfd_follow_gnu_debuglink (bfd *abfd, const char *dir); 216@end example 217@strong{Description}@* 218Takes a BFD and searches it for a .gnu_debuglink section. If this 219section is found, it examines the section for the name and checksum 220of a '.debug' file containing auxiliary debugging information. It 221then searches the filesystem for this .debug file in some standard 222locations, including the directory tree rooted at @var{dir}, and if 223found returns the full filename. 224 225If @var{dir} is NULL, it will search a default path configured into 226libbfd at build time. [XXX this feature is not currently 227implemented]. 228 229@strong{Returns}@* 230@code{NULL} on any errors or failure to locate the .debug file, 231otherwise a pointer to a heap-allocated string containing the 232filename. The caller is responsible for freeing this string. 233 234@findex bfd_create_gnu_debuglink_section 235@subsubsection @code{bfd_create_gnu_debuglink_section} 236@strong{Synopsis} 237@example 238struct bfd_section *bfd_create_gnu_debuglink_section 239 (bfd *abfd, const char *filename); 240@end example 241@strong{Description}@* 242Takes a @var{BFD} and adds a .gnu_debuglink section to it. The section is sized 243to be big enough to contain a link to the specified @var{filename}. 244 245@strong{Returns}@* 246A pointer to the new section is returned if all is ok. Otherwise @code{NULL} is 247returned and bfd_error is set. 248 249@findex bfd_fill_in_gnu_debuglink_section 250@subsubsection @code{bfd_fill_in_gnu_debuglink_section} 251@strong{Synopsis} 252@example 253bfd_boolean bfd_fill_in_gnu_debuglink_section 254 (bfd *abfd, struct bfd_section *sect, const char *filename); 255@end example 256@strong{Description}@* 257Takes a @var{BFD} and containing a .gnu_debuglink section @var{SECT} 258and fills in the contents of the section to contain a link to the 259specified @var{filename}. The filename should be relative to the 260current directory. 261 262@strong{Returns}@* 263@code{TRUE} is returned if all is ok. Otherwise @code{FALSE} is returned 264and bfd_error is set. 265 266