#include "inferior.h"
#include "regcache.h"
#include "gdbthread.h"
+#include "gdb_bfd.h"
#include "gdb_assert.h"
gdb_byte *interp_name;
CORE_ADDR load_addr = 0;
bfd *dyld_bfd = NULL;
+ struct cleanup *cleanup;
/* This method doesn't work with an attached process. */
if (current_inferior ()->attach_flag)
if (!interp_name)
return;
+ cleanup = make_cleanup (null_cleanup, NULL);
+
/* Create a bfd for the interpreter. */
- dyld_bfd = bfd_openr (interp_name, gnutarget);
+ dyld_bfd = gdb_bfd_openr (interp_name, gnutarget);
if (dyld_bfd)
{
bfd *sub;
+ make_cleanup_bfd_unref (dyld_bfd);
sub = bfd_mach_o_fat_extract (dyld_bfd, bfd_object,
gdbarch_bfd_arch_info (target_gdbarch));
if (sub)
- dyld_bfd = sub;
- else
{
- bfd_close (dyld_bfd);
- dyld_bfd = NULL;
+ dyld_bfd = sub;
+ gdb_bfd_ref (sub);
+ make_cleanup_bfd_unref (sub);
}
+ else
+ dyld_bfd = NULL;
}
if (!dyld_bfd)
- return;
+ {
+ do_cleanups (cleanup);
+ return;
+ }
/* We find the dynamic linker's base address by examining
the current pc (which should point at the entry point for the
info->all_image_addr =
lookup_symbol_from_bfd (dyld_bfd, "_dyld_all_image_infos");
- bfd_close (dyld_bfd);
+ do_cleanups (cleanup);
if (info->all_image_addr == 0)
return;
gdbarch_bfd_arch_info (target_gdbarch));
if (!res)
{
- bfd_close (abfd);
- make_cleanup (xfree, found_pathname);
+ make_cleanup_bfd_unref (abfd);
error (_("`%s': not a shared-library: %s"),
- found_pathname, bfd_errmsg (bfd_get_error ()));
+ bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
}
-
- /* Make sure that the filename is malloc'ed. The current filename
- for fat-binaries BFDs is a name that was generated by BFD, usually
- a static string containing the name of the architecture. */
- res->filename = xstrdup (pathname);
-
return res;
}