* remote-mips.c (mips_load_srec): Use make_cleanup_bfd_close.

(pmon_load_fast): Likewise.
	* m32r-rom.c (m32r_load): Use make_cleanup_bfd_close.
	(m32r_upload_command): Likewise.
	* dsrec.c (load_srec): Use make_cleanup_bfd_close.
	* solib-darwin.c (darwin_solib_get_all_image_info_addr_at_init):
	Use make_cleanup_bfd_close.
This commit is contained in:
Tom Tromey
2012-07-18 19:38:39 +00:00
parent a4453b7e0b
commit d6ad71ba41
5 changed files with 41 additions and 6 deletions

View File

@ -1,3 +1,13 @@
2012-07-18 Tom Tromey <tromey@redhat.com>
* remote-mips.c (mips_load_srec): Use make_cleanup_bfd_close.
(pmon_load_fast): Likewise.
* m32r-rom.c (m32r_load): Use make_cleanup_bfd_close.
(m32r_upload_command): Likewise.
* dsrec.c (load_srec): Use make_cleanup_bfd_close.
* solib-darwin.c (darwin_solib_get_all_image_info_addr_at_init):
Use make_cleanup_bfd_close.
2012-07-18 Tom Tromey <tromey@redhat.com> 2012-07-18 Tom Tromey <tromey@redhat.com>
* symfile.c (symfile_bfd_open): Don't copy name. Call * symfile.c (symfile_bfd_open): Don't copy name. Call

View File

@ -57,6 +57,7 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset,
int reclen; int reclen;
time_t start_time, end_time; time_t start_time, end_time;
unsigned long data_count = 0; unsigned long data_count = 0;
struct cleanup *cleanup;
srec = (char *) alloca (maxrecsize + 1); srec = (char *) alloca (maxrecsize + 1);
@ -67,9 +68,11 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset,
return; return;
} }
cleanup = make_cleanup_bfd_close (abfd);
if (bfd_check_format (abfd, bfd_object) == 0) if (bfd_check_format (abfd, bfd_object) == 0)
{ {
printf_filtered (_("File is not an object file\n")); printf_filtered (_("File is not an object file\n"));
do_cleanups (cleanup);
return; return;
} }
@ -171,6 +174,7 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset,
serial_flush_input (desc); serial_flush_input (desc);
report_transfer_performance (data_count, start_time, end_time); report_transfer_performance (data_count, start_time, end_time);
do_cleanups (cleanup);
} }
/* /*

View File

@ -125,6 +125,7 @@ m32r_load (char *filename, int from_tty)
bfd *abfd; bfd *abfd;
unsigned int data_count = 0; unsigned int data_count = 0;
struct timeval start_time, end_time; struct timeval start_time, end_time;
struct cleanup *cleanup;
if (filename == NULL || filename[0] == 0) if (filename == NULL || filename[0] == 0)
filename = get_exec_file (1); filename = get_exec_file (1);
@ -132,6 +133,7 @@ m32r_load (char *filename, int from_tty)
abfd = gdb_bfd_ref (bfd_openr (filename, 0)); abfd = gdb_bfd_ref (bfd_openr (filename, 0));
if (!abfd) if (!abfd)
error (_("Unable to open file %s."), filename); error (_("Unable to open file %s."), filename);
cleanup = make_cleanup_bfd_close (abfd);
if (bfd_check_format (abfd, bfd_object) == 0) if (bfd_check_format (abfd, bfd_object) == 0)
error (_("File is not an object file.")); error (_("File is not an object file."));
gettimeofday (&start_time, NULL); gettimeofday (&start_time, NULL);
@ -189,6 +191,7 @@ m32r_load (char *filename, int from_tty)
confused... */ confused... */
clear_symtab_users (0); clear_symtab_users (0);
do_cleanups (cleanup);
} }
static void static void
@ -435,6 +438,7 @@ m32r_upload_command (char *args, int from_tty)
char buf[1024]; char buf[1024];
struct hostent *hostent; struct hostent *hostent;
struct in_addr inet_addr; struct in_addr inet_addr;
struct cleanup *cleanup;
/* First check to see if there's an ethernet port! */ /* First check to see if there's an ethernet port! */
monitor_printf ("ust\r"); monitor_printf ("ust\r");
@ -526,6 +530,7 @@ m32r_upload_command (char *args, int from_tty)
gettimeofday (&end_time, NULL); gettimeofday (&end_time, NULL);
abfd = gdb_bfd_ref (bfd_openr (args, 0)); abfd = gdb_bfd_ref (bfd_openr (args, 0));
cleanup = make_cleanup_bfd_close (abfd);
if (abfd != NULL) if (abfd != NULL)
{ /* Download is done -- print section statistics. */ { /* Download is done -- print section statistics. */
if (bfd_check_format (abfd, bfd_object) == 0) if (bfd_check_format (abfd, bfd_object) == 0)
@ -566,6 +571,7 @@ m32r_upload_command (char *args, int from_tty)
confused... */ confused... */
clear_symtab_users (0); clear_symtab_users (0);
do_cleanups (cleanup);
} }
/* Provide a prototype to silence -Wmissing-prototypes. */ /* Provide a prototype to silence -Wmissing-prototypes. */

View File

@ -2784,6 +2784,7 @@ mips_load_srec (char *args)
unsigned int i; unsigned int i;
unsigned int srec_frame = 200; unsigned int srec_frame = 200;
int reclen; int reclen;
struct cleanup *cleanup;
static int hashmark = 1; static int hashmark = 1;
buffer = alloca (srec_frame * 2 + 256); buffer = alloca (srec_frame * 2 + 256);
@ -2795,9 +2796,11 @@ mips_load_srec (char *args)
return; return;
} }
cleanup = make_cleanup_bfd_close (abfd);
if (bfd_check_format (abfd, bfd_object) == 0) if (bfd_check_format (abfd, bfd_object) == 0)
{ {
printf_filtered ("File is not an object file\n"); printf_filtered ("File is not an object file\n");
do_cleanups (cleanup);
return; return;
} }
@ -2851,6 +2854,7 @@ mips_load_srec (char *args)
send_srec (srec, reclen, abfd->start_address); send_srec (srec, reclen, abfd->start_address);
serial_flush_input (mips_desc); serial_flush_input (mips_desc);
do_cleanups (cleanup);
} }
/* /*
@ -3367,6 +3371,7 @@ pmon_load_fast (char *file)
int bintotal = 0; int bintotal = 0;
int final = 0; int final = 0;
int finished = 0; int finished = 0;
struct cleanup *cleanup;
buffer = (char *) xmalloc (MAXRECSIZE + 1); buffer = (char *) xmalloc (MAXRECSIZE + 1);
binbuf = (unsigned char *) xmalloc (BINCHUNK); binbuf = (unsigned char *) xmalloc (BINCHUNK);
@ -3377,10 +3382,12 @@ pmon_load_fast (char *file)
printf_filtered ("Unable to open file %s\n", file); printf_filtered ("Unable to open file %s\n", file);
return; return;
} }
cleanup = make_cleanup_bfd_close (abfd);
if (bfd_check_format (abfd, bfd_object) == 0) if (bfd_check_format (abfd, bfd_object) == 0)
{ {
printf_filtered ("File is not an object file\n"); printf_filtered ("File is not an object file\n");
do_cleanups (cleanup);
return; return;
} }
@ -3504,6 +3511,7 @@ pmon_load_fast (char *file)
pmon_end_download (final, bintotal); pmon_end_download (final, bintotal);
} }
do_cleanups (cleanup);
return; return;
} }

View File

@ -357,6 +357,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
gdb_byte *interp_name; gdb_byte *interp_name;
CORE_ADDR load_addr = 0; CORE_ADDR load_addr = 0;
bfd *dyld_bfd = NULL; bfd *dyld_bfd = NULL;
struct cleanup *cleanup;
/* This method doesn't work with an attached process. */ /* This method doesn't work with an attached process. */
if (current_inferior ()->attach_flag) if (current_inferior ()->attach_flag)
@ -367,24 +368,30 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
if (!interp_name) if (!interp_name)
return; return;
cleanup = make_cleanup (null_cleanup, NULL);
/* Create a bfd for the interpreter. */ /* Create a bfd for the interpreter. */
dyld_bfd = gdb_bfd_ref (bfd_openr (interp_name, gnutarget)); dyld_bfd = gdb_bfd_ref (bfd_openr (interp_name, gnutarget));
if (dyld_bfd) if (dyld_bfd)
{ {
bfd *sub; bfd *sub;
make_cleanup_bfd_close (dyld_bfd);
sub = bfd_mach_o_fat_extract (dyld_bfd, bfd_object, sub = bfd_mach_o_fat_extract (dyld_bfd, bfd_object,
gdbarch_bfd_arch_info (target_gdbarch)); gdbarch_bfd_arch_info (target_gdbarch));
if (sub) if (sub)
dyld_bfd = sub;
else
{ {
gdb_bfd_unref (dyld_bfd); dyld_bfd = gdb_bfd_ref (sub);
make_cleanup_bfd_close (sub);
}
else
dyld_bfd = NULL; dyld_bfd = NULL;
} }
}
if (!dyld_bfd) if (!dyld_bfd)
{
do_cleanups (cleanup);
return; return;
}
/* We find the dynamic linker's base address by examining /* We find the dynamic linker's base address by examining
the current pc (which should point at the entry point for the the current pc (which should point at the entry point for the
@ -396,7 +403,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
info->all_image_addr = info->all_image_addr =
lookup_symbol_from_bfd (dyld_bfd, "_dyld_all_image_infos"); lookup_symbol_from_bfd (dyld_bfd, "_dyld_all_image_infos");
gdb_bfd_unref (dyld_bfd); do_cleanups (cleanup);
if (info->all_image_addr == 0) if (info->all_image_addr == 0)
return; return;