* objdump.c (display_file): Close each archive element after it

has been displayed.
This commit is contained in:
Ian Lance Taylor
1994-03-29 21:34:44 +00:00
parent 4aa6fe102d
commit 8f197c94e3
2 changed files with 58 additions and 41 deletions

View File

@ -2,6 +2,7 @@ Tue Mar 29 14:59:04 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
* nm.c (display_archive): Close each archive element after it has * nm.c (display_archive): Close each archive element after it has
been displayed. been displayed.
* objdump.c (display_file): Likewise.
Mon Mar 28 13:04:08 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com) Mon Mar 28 13:04:08 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)

View File

@ -86,6 +86,9 @@ dump_symbols PARAMS ((bfd *abfd));
static void static void
display_bfd PARAMS ((bfd *abfd)); display_bfd PARAMS ((bfd *abfd));
static void
objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
void void
usage (stream, status) usage (stream, status)
@ -250,7 +253,7 @@ compare_symbols (ap, bp)
/* Print VMA symbolically to INFO if possible. */ /* Print VMA symbolically to INFO if possible. */
void static void
objdump_print_address (vma, info) objdump_print_address (vma, info)
bfd_vma vma; bfd_vma vma;
struct disassemble_info *info; struct disassemble_info *info;
@ -266,54 +269,41 @@ objdump_print_address (vma, info)
/* Indices in `syms'. */ /* Indices in `syms'. */
unsigned int min = 0; unsigned int min = 0;
unsigned int max = symcount; unsigned int max = symcount;
unsigned int thisplace = 1; unsigned int thisplace;
unsigned int oldthisplace;
int vardiff; bfd_signed_vma vardiff;
fprintf_vma (info->stream, vma); fprintf_vma (info->stream, vma);
if (symcount < 1) if (symcount < 1)
return; return;
/* Perform a binary search looking for the closest symbol to /* Perform a binary search looking for the closest symbol to the
the required value. */ required value. We are searching the range (min, max]. */
while (true) while (min + 1 < max)
{ {
asymbol *sym; asymbol *sym;
#if 0
asection *sym_sec;
#endif
oldthisplace = thisplace;
thisplace = (max + min) / 2; thisplace = (max + min) / 2;
if (thisplace == oldthisplace)
break;
sym = syms[thisplace]; sym = syms[thisplace];
vardiff = sym->value - vma; vardiff = sym->value - vma;
#if 0
sym_sec = sym->section;
#endif
if (vardiff > 0) if (vardiff > 0)
max = thisplace; max = thisplace;
else if (vardiff < 0) else if (vardiff < 0)
min = thisplace; min = thisplace;
else else
goto found;
}
/* We've run out of places to look; see whether this or the
symbol before this describes this location the best. */
if (thisplace != 0)
{ {
if (syms[thisplace - 1]->value - vma < syms[thisplace]->value - vma) min = thisplace;
{ break;
/* Previous symbol is in correct section and is closer. */
thisplace--;
} }
} }
found: /* The symbol we want is now in min, the low end of the range we
were searching. */
thisplace = min;
{ {
/* If this symbol isn't global, search for one with the same value /* If this symbol isn't global, search for one with the same value
that is. */ that is. */
@ -364,9 +354,15 @@ objdump_print_address (vma, info)
&& syms[thisplace]->section != aux->sec) && syms[thisplace]->section != aux->sec)
{ {
for (i = thisplace + 1; i < symcount; i++) for (i = thisplace + 1; i < symcount; i++)
{
if (syms[i]->value != syms[thisplace]->value) if (syms[i]->value != syms[thisplace]->value)
{
i--;
break; break;
while (--i >= 0) }
}
for (; i >= 0; i--)
{
if (syms[i]->section == aux->sec) if (syms[i]->section == aux->sec)
{ {
thisplace = i; thisplace = i;
@ -374,6 +370,7 @@ objdump_print_address (vma, info)
} }
} }
} }
}
fprintf (info->stream, " <%s", syms[thisplace]->name); fprintf (info->stream, " <%s", syms[thisplace]->name);
if (syms[thisplace]->value > vma) if (syms[thisplace]->value > vma)
{ {
@ -405,6 +402,7 @@ objdump_print_address (vma, info)
#define ARCH_m68k #define ARCH_m68k
#define ARCH_m88k #define ARCH_m88k
#define ARCH_mips #define ARCH_mips
#define ARCH_powerpc
#define ARCH_rs6000 #define ARCH_rs6000
#define ARCH_sh #define ARCH_sh
#define ARCH_sparc #define ARCH_sparc
@ -527,6 +525,14 @@ disassemble_data (abfd)
disassemble = print_insn_little_mips; disassemble = print_insn_little_mips;
break; break;
#endif #endif
#ifdef ARCH_powerpc
case bfd_arch_powerpc:
if (abfd->xvec->byteorder_big_p)
disassemble = print_insn_big_powerpc;
else
disassemble = print_insn_little_powerpc;
break;
#endif
#ifdef ARCH_rs6000 #ifdef ARCH_rs6000
case bfd_arch_rs6000: case bfd_arch_rs6000:
disassemble = print_insn_rs6000; disassemble = print_insn_rs6000;
@ -908,7 +914,7 @@ display_bfd (abfd)
if (!bfd_check_format_matches (abfd, bfd_object, &matching)) if (!bfd_check_format_matches (abfd, bfd_object, &matching))
{ {
bfd_nonfatal (bfd_get_filename (abfd)); bfd_nonfatal (bfd_get_filename (abfd));
if (bfd_error == file_ambiguously_recognized) if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
{ {
list_matching_formats (matching); list_matching_formats (matching);
free (matching); free (matching);
@ -959,24 +965,32 @@ display_file (filename, target)
if (bfd_check_format (file, bfd_archive) == true) if (bfd_check_format (file, bfd_archive) == true)
{ {
bfd *last_arfile = NULL;
printf ("In archive %s:\n", bfd_get_filename (file)); printf ("In archive %s:\n", bfd_get_filename (file));
for (;;) for (;;)
{ {
bfd_error = no_error; bfd_set_error (bfd_error_no_error);
arfile = bfd_openr_next_archived_file (file, arfile); arfile = bfd_openr_next_archived_file (file, arfile);
if (arfile == NULL) if (arfile == NULL)
{ {
if (bfd_error != no_more_archived_files) if (bfd_get_error () != bfd_error_no_more_archived_files)
{ {
bfd_nonfatal (bfd_get_filename (file)); bfd_nonfatal (bfd_get_filename (file));
} }
return; break;
} }
display_bfd (arfile); display_bfd (arfile);
/* Don't close the archive elements; we need them for next_archive */
if (last_arfile != NULL)
bfd_close (last_arfile);
last_arfile = arfile;
} }
if (last_arfile != NULL)
bfd_close (last_arfile);
} }
else else
display_bfd (file); display_bfd (file);
@ -1322,8 +1336,10 @@ main (argc, argv)
char *target = default_target; char *target = default_target;
boolean seenflag = false; boolean seenflag = false;
bfd_init ();
program_name = *argv; program_name = *argv;
xmalloc_set_program_name (program_name);
bfd_init ();
while ((c = getopt_long (argc, argv, "ib:m:Vdlfahrtxsj:", long_options, while ((c = getopt_long (argc, argv, "ib:m:Vdlfahrtxsj:", long_options,
(int *) 0)) (int *) 0))