Next: bfd_init, Previous: typedef bfd, Up: BFD Front End [Contents][Index]
Most BFD functions return nonzero on success (check their
individual documentation for precise semantics). On an error,
they call bfd_set_error to set an error condition that callers
can check by calling bfd_get_error.
If that returns bfd_error_system_call, then check
errno.
The easiest way to report a BFD error to the user is to
use bfd_perror.
The BFD error is thread-local.
bfd_error_type ¶The values returned by bfd_get_error are defined by the
enumerated type bfd_error_type.
typedef enum bfd_error
{
bfd_error_no_error = 0,
bfd_error_system_call,
bfd_error_invalid_target,
bfd_error_wrong_format,
bfd_error_wrong_object_format,
bfd_error_invalid_operation,
bfd_error_no_memory,
bfd_error_no_symbols,
bfd_error_no_armap,
bfd_error_no_more_archived_files,
bfd_error_malformed_archive,
bfd_error_missing_dso,
bfd_error_file_not_recognized,
bfd_error_file_ambiguously_recognized,
bfd_error_no_contents,
bfd_error_nonrepresentable_section,
bfd_error_no_debug_section,
bfd_error_bad_value,
bfd_error_file_truncated,
bfd_error_file_too_big,
bfd_error_sorry,
bfd_error_on_input,
bfd_error_invalid_error_code
}
bfd_error_type;
bfd_get_error ¶bfd_error_type bfd_get_error (void); ¶Return the current BFD error condition.
bfd_set_error ¶void bfd_set_error (bfd_error_type error_tag); ¶Set the BFD error condition to be error_tag.
error_tag must not be bfd_error_on_input. Use bfd_set_input_error for input errors instead.
bfd_set_input_error ¶void bfd_set_input_error (bfd *input, bfd_error_type error_tag); ¶Set the BFD error condition to be bfd_error_on_input. input is the input bfd where the error occurred, and error_tag the bfd_error_type error.
bfd_errmsg ¶const char *bfd_errmsg (bfd_error_type error_tag); ¶Return a string describing the error error_tag, or
the system error if error_tag is bfd_error_system_call.
bfd_perror ¶void bfd_perror (const char *message); ¶Print to the standard error stream a string describing the last BFD error that occurred, or the last system error if the last BFD error was a system call failure. If message is non-NULL and non-empty, the error string printed is preceded by message, a colon, and a space. It is followed by a newline.
bfd_asprintf ¶char *bfd_asprintf (const char *fmt, ...); ¶Primarily for error reporting, this function is like libiberty’s xasprintf except that it can return NULL on no memory and the returned string should not be freed. Uses a thread-local malloc’d buffer managed by libbfd, _bfd_error_buf. Be aware that a call to this function frees the result of any previous call. bfd_errmsg (bfd_error_on_input) also calls this function.
Some BFD functions want to print messages describing the problem. They call a BFD error handler function. This function may be overridden by the program.
The BFD error handler acts like vprintf.
typedef void (*bfd_error_handler_type) (const char *, va_list);
typedef int (*bfd_print_callback) (void *, const char *, ...);
bfd_print_error_bfd_error_handlerbfd_set_error_handler_bfd_set_error_handler_caching_bfd_restore_error_handler_cachingbfd_set_error_program_name_bfd_get_error_program_namebfd_print_error ¶void bfd_print_error (bfd_print_callback print_func, void *stream, const char *fmt, va_list ap); ¶This formats FMT and AP according to BFD "printf" rules, sending the output to STREAM by repeated calls to PRINT_FUNC. PRINT_FUNC is a printf-like function; it does not need to implement the BFD printf format extensions. This can be used in a callback that is set via bfd_set_error_handler to turn the error into ordinary output.
_bfd_error_handler ¶void _bfd_error_handler (const char *fmt, ...) ATTRIBUTE_PRINTF_1; ¶This is the default routine to handle BFD error messages. Like fprintf (stderr, ...), but also handles some extra format specifiers.
%pA section name from section. For group components, prints group name too. %pB file name from bfd. For archive components, prints archive too.
Beware: Only supports a maximum of 9 format arguments.
bfd_set_error_handler ¶bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type); ¶Set the BFD error handler function. Returns the previous function.
_bfd_set_error_handler_caching ¶struct per_xvec_messages *_bfd_set_error_handler_caching (struct per_xvec_messages *); ¶Set the BFD error handler function to one that stores messages to the per_xvec_messages object. Returns the previous object to which messages are stored. Note that two sequential calls to this with a non-NULL argument will cause output to be dropped, rather than gathered.
_bfd_restore_error_handler_caching ¶void _bfd_restore_error_handler_caching (struct per_xvec_messages *); ¶Reset the BFD error handler object to an earlier value.
If BFD finds an internal inconsistency, the bfd assert handler is called with information on the BFD version, BFD source file and line. If this happens, most programs linked against BFD are expected to want to exit with an error, or mark the current BFD operation as failed, so it is recommended to override the default handler, which just calls _bfd_error_handler and continues.
typedef void (*bfd_assert_handler_type) (const char *bfd_formatmsg,
const char *bfd_version,
const char *bfd_file,
int bfd_line);
Next: bfd_init, Previous: typedef bfd, Up: BFD Front End [Contents][Index]