* objdump.c (syms2): Removed unused variable.

* objdump.c (remove_useless_symbols):  New function.
	* objdump.c (comp):  Simplify.
	* objdump.c (dis-assemble_data):  Make simpler and more
	efficient how we filter out useless symbols:  Just filter
	BEFORE the sort (using remove_useless_symbols).
	* objdump.c (objdump_print_address):  Simplify.
	Change output syntax to match gdb.
This commit is contained in:
Per Bothner 1993-06-18 21:37:21 +00:00
parent d4bbd6ace2
commit 3ae36cb686
2 changed files with 76 additions and 85 deletions

View File

@ -1,3 +1,14 @@
Fri Jun 18 14:29:12 1993 Per Bothner (bothner@deneb.cygnus.com)
* objdump.c (syms2): Removed unused variable.
* objdump.c (remove_useless_symbols): New function.
* objdump.c (comp): Simplify.
* objdump.c (dis-assemble_data): Make simpler and more
efficient how we filter out useless symbols: Just filter
BEFORE the sort (using remove_useless_symbols).
* objdump.c (objdump_print_address): Simplify.
Change output syntax to match gdb.
Thu Jun 17 16:53:56 1993 david d `zoo' zuhn (zoo@cygnus.com) Thu Jun 17 16:53:56 1993 david d `zoo' zuhn (zoo@cygnus.com)
* Makefile.in: canonicalize install.sh; for use within * Makefile.in: canonicalize install.sh; for use within

View File

@ -65,7 +65,6 @@ char *only;
char *machine = (char *) NULL; char *machine = (char *) NULL;
asymbol **syms; asymbol **syms;
asymbol **syms2;
unsigned int storage; unsigned int storage;
@ -180,6 +179,34 @@ DEFUN (slurp_symtab, (abfd),
return sy; return sy;
} }
/* Filter out (in place) symbols that are useless for dis-assemble.
Return count of useful symbols. */
int remove_useless_symbols (syms, count)
asymbol **syms;
int count;
{
register asymbol **in_ptr = syms;
register asymbol **out_ptr = syms;
while ( --count >= 0 )
{
asymbol *sym = *in_ptr++;
if (sym->name == NULL || sym->name[0] == '\0')
continue;
if (sym->flags & (BSF_DEBUGGING))
continue;
if (sym->section == &bfd_und_section
|| bfd_is_com_section (sym->section))
continue;
*out_ptr++ = sym;
}
return out_ptr - syms;
}
/* Sort symbols into value order */ /* Sort symbols into value order */
static int static int
comp (ap, bp) comp (ap, bp)
@ -188,29 +215,17 @@ comp (ap, bp)
{ {
asymbol *a = *(asymbol **)ap; asymbol *a = *(asymbol **)ap;
asymbol *b = *(asymbol **)bp; asymbol *b = *(asymbol **)bp;
int diff;
bfd *a_bfd, *b_bfd;
if (a->name == (char *) NULL || (a->flags & (BSF_DEBUGGING))) if (a->value > b->value)
a_bfd = 0; return 1;
else else if (a->value < b->value)
a_bfd = bfd_asymbol_bfd(a); return -1;
if (b->name == (char *) NULL || (b->flags & (BSF_DEBUGGING)))
b_bfd = 0;
else
b_bfd = bfd_asymbol_bfd(b);
diff = a_bfd - b_bfd; if (a->section > b->section)
if (diff) return 1;
{ else if (a->section < b->section)
return -diff; return -1;
} return 0;
diff = a->value - b->value;
if (diff)
{
return diff;
}
return a->section - b->section;
} }
/* Print the supplied address symbolically if possible */ /* Print the supplied address symbolically if possible */
@ -230,53 +245,27 @@ objdump_print_address (vma, info)
int vardiff; int vardiff;
if (symcount == 0) fprintf_vma (info->stream, vma);
{
fprintf_vma (info->stream, vma); if (symcount > 0)
}
else
{ {
while (true) while (true)
{ {
asymbol *sym; asection *sym_sec;
oldthisplace = thisplace; oldthisplace = thisplace;
thisplace = (max + min) / 2; thisplace = (max + min) / 2;
if (thisplace == oldthisplace) if (thisplace == oldthisplace)
break; break;
vardiff = syms[thisplace]->value - vma; sym = syms[thisplace];
vardiff = sym->value - vma;
sym_sec = sym->section;
if (vardiff if (vardiff > 0)
/* Check that the value isn't merely a coincidence. max = thisplace;
(if not checked, we might print some undefined symbol else if (vardiff < 0)
for the address 0 rather than "main", for example. */ min = thisplace;
|| !(syms[thisplace]->flags & (BSF_GLOBAL|BSF_LOCAL)))
{
if (vardiff > 0)
{
max = thisplace;
}
else
{
min = thisplace;
}
}
else else
{ goto found;
/* Totally awesome! the exact right symbol */
CONST char *match_name = syms[thisplace]->name;
int sym_len = strlen (match_name);
/* Avoid "filename.o" as a match */
if (sym_len > 2
&& match_name[sym_len - 2] == '.'
&& match_name[sym_len - 1] == 'o'
&& thisplace + 1 < symcount
&& syms[thisplace + 1]->value == vma)
match_name = syms[thisplace + 1]->name;
/* Totally awesome! the exact right symbol */
fprintf_vma (info->stream, vma);
fprintf (info->stream, " (%s+)0000", syms[thisplace]->name);
return;
}
} }
/* We've run out of places to look, print the symbol before this one /* We've run out of places to look, print the symbol before this one
see if this or the symbol before describes this location the best */ see if this or the symbol before describes this location the best */
@ -291,17 +280,17 @@ objdump_print_address (vma, info)
} }
} }
fprintf_vma (info->stream, vma); found:
fprintf (info->stream, " <%s", syms[thisplace]->name);
if (syms[thisplace]->value > vma) if (syms[thisplace]->value > vma)
{ {
fprintf (info->stream, " (%s-)", syms[thisplace]->name); fprintf (info->stream, "-%04x", syms[thisplace]->value - vma);
fprintf (info->stream, "%04x", syms[thisplace]->value - vma);
} }
else else if (vma > syms[thisplace]->value)
{ {
fprintf (info->stream, " (%s+)", syms[thisplace]->name); fprintf (info->stream, "+%04x", vma - syms[thisplace]->value);
fprintf (info->stream, "%04x", vma - syms[thisplace]->value);
} }
fprintf (info->stream, ">");
} }
} }
@ -315,7 +304,6 @@ disassemble_data (abfd)
bfd_size_type i; bfd_size_type i;
unsigned int (*print) ()= 0; /* Old style */ unsigned int (*print) ()= 0; /* Old style */
disassembler_ftype disassemble = 0; /* New style */ disassembler_ftype disassemble = 0; /* New style */
unsigned int print_insn_h8300 ();
enum bfd_architecture a; enum bfd_architecture a;
struct disassemble_info disasm_info; struct disassemble_info disasm_info;
@ -335,28 +323,11 @@ disassemble_data (abfd)
syms[i]->value += syms[i]->section->vma; syms[i]->value += syms[i]->section->vma;
} }
/* We keep a copy of the symbols in the original order */ symcount = remove_useless_symbols (syms, symcount);
syms2 = slurp_symtab (abfd);
/* Sort the symbols into section and symbol order */ /* Sort the symbols into section and symbol order */
(void) qsort (syms, symcount, sizeof (asymbol *), comp); (void) qsort (syms, symcount, sizeof (asymbol *), comp);
/* Find the first useless symbol */
{
unsigned int i;
for (i = 0; i < symcount; i++)
{
if (syms[i]->name == (char *) NULL
|| (syms[i]->flags & BSF_DEBUGGING) != 0)
{
symcount = i;
break;
}
}
}
if (machine != (char *) NULL) if (machine != (char *) NULL)
{ {
info = bfd_scan_arch (machine); info = bfd_scan_arch (machine);
@ -396,6 +367,12 @@ disassemble_data (abfd)
case bfd_arch_h8500: case bfd_arch_h8500:
disassemble = print_insn_h8500; disassemble = print_insn_h8500;
break; break;
case bfd_arch_h8300:
if (bfd_get_mach(abfd) == bfd_mach_h8300h)
disassemble = print_insn_h8300h;
else
disassemble = print_insn_h8300;
break;
case bfd_arch_sh: case bfd_arch_sh:
disassemble = print_insn_sh; disassemble = print_insn_sh;
break; break;
@ -737,6 +714,8 @@ display_bfd (abfd)
dump_relocs (abfd); dump_relocs (abfd);
if (dump_section_contents) if (dump_section_contents)
dump_data (abfd); dump_data (abfd);
/* Note that disassemble_data re-orders the syms table, but that is
safe - as long as it is done last! */
if (disassemble) if (disassemble)
disassemble_data (abfd); disassemble_data (abfd);
} }
@ -911,6 +890,7 @@ dump_relocs (abfd)
arelent **p; arelent **p;
relpp = (arelent **) xmalloc (bfd_get_reloc_upper_bound (abfd, a)); relpp = (arelent **) xmalloc (bfd_get_reloc_upper_bound (abfd, a));
/* Note that this must be done *before* we sort the syms table. */
relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms); relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
if (relcount == 0) if (relcount == 0)
{ {