X-Git-Url: http://drtracing.org/?a=blobdiff_plain;ds=sidebyside;f=binutils%2Fobjdump.c;h=6488f9f061558fdc0f8cc4114b5fcf1f53cd2bbc;hb=026df7c5e64e4a8de40c8d744980b511bcce983d;hp=a6658313fe6a36fecb6b3f44b7e6bbedc9da8381;hpb=8b1e6df337acf62900dda4e8aad874b999563510;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/objdump.c b/binutils/objdump.c index a6658313fe..6488f9f061 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -1,28 +1,30 @@ /* objdump.c -- dump information about an object file. - Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 + Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, + 2000, 2001, 2002 Free Software Foundation, Inc. -This file is part of GNU Binutils. + This file is part of GNU Binutils. -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bfd.h" -#include "getopt.h" #include "progress.h" #include "bucomm.h" -#include +#include "budemang.h" +#include "getopt.h" +#include "safe-ctype.h" #include "dis-asm.h" #include "libiberty.h" #include "demangle.h" @@ -72,7 +74,8 @@ static bfd_vma adjust_section_vma = 0; /* --adjust-vma */ static int file_start_context = 0; /* --file-start-context */ /* Extra info to pass to the disassembler address printing function. */ -struct objdump_disasm_info { +struct objdump_disasm_info +{ bfd *abfd; asection *sec; boolean require_sec; @@ -107,122 +110,62 @@ static long dynsymcount = 0; /* Static declarations. */ -static void -usage PARAMS ((FILE *, int)); - -static void -nonfatal PARAMS ((const char *)); - -static void -display_file PARAMS ((char *filename, char *target)); - -static void -dump_section_header PARAMS ((bfd *, asection *, PTR)); - -static void -dump_headers PARAMS ((bfd *)); - -static void -dump_data PARAMS ((bfd *abfd)); - -static void -dump_relocs PARAMS ((bfd *abfd)); - -static void -dump_dynamic_relocs PARAMS ((bfd * abfd)); - -static void -dump_reloc_set PARAMS ((bfd *, asection *, arelent **, long)); - -static void -dump_symbols PARAMS ((bfd *abfd, boolean dynamic)); - -static void -dump_bfd_header PARAMS ((bfd *)); - -static void -dump_bfd_private_header PARAMS ((bfd *)); - -static void -display_bfd PARAMS ((bfd *abfd)); - -static void -display_target_list PARAMS ((void)); - -static void -display_info_table PARAMS ((int, int)); - -static void -display_target_tables PARAMS ((void)); - -static void -display_info PARAMS ((void)); - -static void -objdump_print_value PARAMS ((bfd_vma, struct disassemble_info *, boolean)); - -static void -objdump_print_symname PARAMS ((bfd *, struct disassemble_info *, asymbol *)); - -static asymbol * -find_symbol_for_address PARAMS ((bfd *, asection *, bfd_vma, boolean, long *)); - -static void -objdump_print_addr_with_sym PARAMS ((bfd *, asection *, asymbol *, bfd_vma, - struct disassemble_info *, boolean)); - -static void -objdump_print_addr PARAMS ((bfd_vma, struct disassemble_info *, boolean)); - -static void -objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *)); - -static void -show_line PARAMS ((bfd *, asection *, bfd_vma)); - -static void -disassemble_bytes PARAMS ((struct disassemble_info *, disassembler_ftype, - boolean, bfd_byte *, bfd_vma, bfd_vma, - arelent ***, arelent **)); - -static void -disassemble_data PARAMS ((bfd *)); - -static const char * -endian_string PARAMS ((enum bfd_endian)); - -static asymbol ** -slurp_symtab PARAMS ((bfd *)); - -static asymbol ** -slurp_dynamic_symtab PARAMS ((bfd *)); - -static long -remove_useless_symbols PARAMS ((asymbol **, long)); - -static int -compare_symbols PARAMS ((const PTR, const PTR)); - -static int -compare_relocs PARAMS ((const PTR, const PTR)); - -static void -dump_stabs PARAMS ((bfd *)); - -static boolean -read_section_stabs PARAMS ((bfd *, const char *, const char *)); - -static void -print_section_stabs PARAMS ((bfd *, const char *, const char *)); +static void usage PARAMS ((FILE *, int)); +static void nonfatal PARAMS ((const char *)); +static void display_file PARAMS ((char *filename, char *target)); +static void dump_section_header PARAMS ((bfd *, asection *, PTR)); +static void dump_headers PARAMS ((bfd *)); +static void dump_data PARAMS ((bfd *abfd)); +static void dump_relocs PARAMS ((bfd *abfd)); +static void dump_dynamic_relocs PARAMS ((bfd * abfd)); +static void dump_reloc_set PARAMS ((bfd *, asection *, arelent **, long)); +static void dump_symbols PARAMS ((bfd *abfd, boolean dynamic)); +static void dump_bfd_header PARAMS ((bfd *)); +static void dump_bfd_private_header PARAMS ((bfd *)); +static void dump_bfd PARAMS ((bfd *)); +static void display_bfd PARAMS ((bfd *abfd)); +static void display_target_list PARAMS ((void)); +static void display_info_table PARAMS ((int, int)); +static void display_target_tables PARAMS ((void)); +static void display_info PARAMS ((void)); +static void objdump_print_value + PARAMS ((bfd_vma, struct disassemble_info *, boolean)); +static void objdump_print_symname + PARAMS ((bfd *, struct disassemble_info *, asymbol *)); +static asymbol *find_symbol_for_address + PARAMS ((bfd *, asection *, bfd_vma, boolean, long *)); +static void objdump_print_addr_with_sym + PARAMS ((bfd *, asection *, asymbol *, bfd_vma, + struct disassemble_info *, boolean)); +static void objdump_print_addr + PARAMS ((bfd_vma, struct disassemble_info *, boolean)); +static void objdump_print_address + PARAMS ((bfd_vma, struct disassemble_info *)); +static int objdump_symbol_at_address + PARAMS ((bfd_vma, struct disassemble_info *)); +static void show_line PARAMS ((bfd *, asection *, bfd_vma)); +static void disassemble_bytes + PARAMS ((struct disassemble_info *, disassembler_ftype, boolean, + bfd_byte *, bfd_vma, bfd_vma, arelent ***, arelent **)); +static void disassemble_data PARAMS ((bfd *)); +static const char *endian_string PARAMS ((enum bfd_endian)); +static asymbol ** slurp_symtab PARAMS ((bfd *)); +static asymbol ** slurp_dynamic_symtab PARAMS ((bfd *)); +static long remove_useless_symbols PARAMS ((asymbol **, long)); +static int compare_symbols PARAMS ((const PTR, const PTR)); +static int compare_relocs PARAMS ((const PTR, const PTR)); +static void dump_stabs PARAMS ((bfd *)); +static boolean read_section_stabs PARAMS ((bfd *, const char *, const char *)); +static void print_section_stabs PARAMS ((bfd *, const char *, const char *)); static void usage (stream, status) FILE *stream; int status; { - fprintf (stream, _("Usage: %s OPTION... FILE...\n"), program_name); - fprintf (stream, _("Display information from object FILE.\n")); - fprintf (stream, _("\n At least one of the following switches must be given:\n")); + fprintf (stream, _("Usage: %s \n"), program_name); + fprintf (stream, _(" Display information from object .\n")); + fprintf (stream, _(" At least one of the following switches must be given:\n")); fprintf (stream, _("\ -a, --archive-headers Display archive header information\n\ -f, --file-headers Display the contents of the overall file header\n\ @@ -239,7 +182,7 @@ usage (stream, status) -T, --dynamic-syms Display the contents of the dynamic symbol table\n\ -r, --reloc Display the relocation entries in the file\n\ -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\ - -V, --version Display this program's version number\n\ + -v, --version Display this program's version number\n\ -i, --info List object formats and architectures supported\n\ -H, --help Display this information\n\ ")); @@ -257,7 +200,7 @@ usage (stream, status) -l, --line-numbers Include line numbers and filenames in output\n\ -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\ The STYLE, if specified, can be `auto', 'gnu',\n\ - 'lucid', 'arm', 'hp', 'edg', or 'gnu-new-abi'\n\ + 'lucid', 'arm', 'hp', 'edg', or 'gnu-v3'\n\ -w, --wide Format output for more than 80 columns\n\ -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\ --start-address=ADDR Only process data whoes address is >= ADDR\n\ @@ -267,6 +210,7 @@ usage (stream, status) --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\ \n")); list_supported_targets (program_name, stream); + list_supported_architectures (program_name, stream); disassembler_usage (stream); } @@ -342,10 +286,10 @@ dump_section_header (abfd, section, ignored) printf ("%3d %-13s %08lx ", section->index, bfd_get_section_name (abfd, section), (unsigned long) bfd_section_size (abfd, section) / opb); - printf_vma (bfd_get_section_vma (abfd, section)); + bfd_printf_vma (abfd, bfd_get_section_vma (abfd, section)); printf (" "); - printf_vma (section->lma); - printf (" %08lx 2**%u", section->filepos, + bfd_printf_vma (abfd, section->lma); + printf (" %08lx 2**%u", (unsigned long) section->filepos, bfd_get_section_alignment (abfd, section)); if (! wide_output) printf ("\n "); @@ -357,14 +301,8 @@ dump_section_header (abfd, section, ignored) PF (SEC_HAS_CONTENTS, "CONTENTS"); PF (SEC_ALLOC, "ALLOC"); PF (SEC_CONSTRUCTOR, "CONSTRUCTOR"); - PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT"); - PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA"); - PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS"); PF (SEC_LOAD, "LOAD"); PF (SEC_RELOC, "RELOC"); -#ifdef SEC_BALIGN - PF (SEC_BALIGN, "BALIGN"); -#endif PF (SEC_READONLY, "READONLY"); PF (SEC_CODE, "CODE"); PF (SEC_DATA, "DATA"); @@ -377,6 +315,8 @@ dump_section_header (abfd, section, ignored) PF (SEC_CLINK, "CLINK"); PF (SEC_SMALL_DATA, "SMALL_DATA"); PF (SEC_SHARED, "SHARED"); + PF (SEC_ARCH_BIT_0, "ARCH_BIT_0"); + PF (SEC_THREAD_LOCAL, "THREAD_LOCAL"); if ((section->flags & SEC_LINK_ONCE) != 0) { @@ -421,11 +361,17 @@ dump_headers (abfd) #ifndef BFD64 printf (_("Idx Name Size VMA LMA File off Algn")); #else - printf (_("Idx Name Size VMA LMA File off Algn")); + /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */ + if (bfd_get_arch_size (abfd) == 32) + printf (_("Idx Name Size VMA LMA File off Algn")); + else + printf (_("Idx Name Size VMA LMA File off Algn")); #endif if (wide_output) printf (_(" Flags")); + if (abfd->flags & HAS_LOAD_PAGE) + printf (_(" Pg")); printf ("\n"); bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL); @@ -440,7 +386,6 @@ slurp_symtab (abfd) if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) { - non_fatal (_("%s: no symbols"), bfd_get_filename (abfd)); symcount = 0; return NULL; } @@ -448,16 +393,12 @@ slurp_symtab (abfd) storage = bfd_get_symtab_upper_bound (abfd); if (storage < 0) bfd_fatal (bfd_get_filename (abfd)); - if (storage) - { - sy = (asymbol **) xmalloc (storage); - } + sy = (asymbol **) xmalloc (storage); + symcount = bfd_canonicalize_symtab (abfd, sy); if (symcount < 0) bfd_fatal (bfd_get_filename (abfd)); - if (symcount == 0) - non_fatal (_("%s: no symbols"), bfd_get_filename (abfd)); return sy; } @@ -482,22 +423,18 @@ slurp_dynamic_symtab (abfd) bfd_fatal (bfd_get_filename (abfd)); } - if (storage) - { - sy = (asymbol **) xmalloc (storage); - } + sy = (asymbol **) xmalloc (storage); + dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy); if (dynsymcount < 0) bfd_fatal (bfd_get_filename (abfd)); - if (dynsymcount == 0) - non_fatal (_("%s: No dynamic symbols"), bfd_get_filename (abfd)); return sy; } /* Filter out (in place) symbols that are useless for disassembly. COUNT is the number of elements in SYMBOLS. - Return the number of useful symbols. */ + Return the number of useful symbols. */ static long remove_useless_symbols (symbols, count) @@ -525,7 +462,7 @@ remove_useless_symbols (symbols, count) /* Sort symbols into value order. */ -static int +static int compare_symbols (ap, bp) const PTR ap; const PTR bp; @@ -666,8 +603,10 @@ objdump_print_value (vma, info, skip_zeroes) { char buf[30]; char *p; + struct objdump_disasm_info *aux + = (struct objdump_disasm_info *) info->application_data; - sprintf_vma (buf, vma); + bfd_sprintf_vma (aux->abfd, buf, vma); if (! skip_zeroes) p = buf; else @@ -690,29 +629,20 @@ objdump_print_symname (abfd, info, sym) { char *alloc; const char *name; - const char *print; alloc = NULL; name = bfd_asymbol_name (sym); - if (! do_demangle || name[0] == '\0') - print = name; - else + if (do_demangle && name[0] != '\0') { /* Demangle the name. */ - if (bfd_get_symbol_leading_char (abfd) == name[0]) - ++name; - - alloc = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS); - if (alloc == NULL) - print = name; - else - print = alloc; + alloc = demangle (abfd, name); + name = alloc; } if (info != NULL) - (*info->fprintf_func) (info->stream, "%s", print); + (*info->fprintf_func) (info->stream, "%s", name); else - printf ("%s", print); + printf ("%s", name); if (alloc != NULL) free (alloc); @@ -740,7 +670,7 @@ find_symbol_for_address (abfd, sec, vma, require_sec, place) long min = 0; long max = sorted_symcount; long thisplace; - unsigned int opb = bfd_octets_per_byte (abfd); + unsigned int opb = bfd_octets_per_byte (abfd); if (sorted_symcount < 1) return NULL; @@ -777,7 +707,7 @@ find_symbol_for_address (abfd, sec, vma, require_sec, place) /* If the file is relocateable, and the symbol could be from this section, prefer a symbol from this section over symbols from others, even if the other symbol's value might be closer. - + Note that this may be wrong for some symbol references if the sections have overlapping memory ranges, but in that case there's no way to tell what's desired without looking at the relocation @@ -1006,7 +936,7 @@ skip_to_line (p, line, show) if (strchr (buf, '\n') != NULL) ++p->line; } -} +} /* Show the line number, or the source line, in a dissassembly listing. */ @@ -1017,8 +947,8 @@ show_line (abfd, section, addr_offset) asection *section; bfd_vma addr_offset; { - CONST char *filename; - CONST char *functionname; + const char *filename; + const char *functionname; unsigned int line; if (! with_line_numbers && ! with_source_code) @@ -1127,10 +1057,10 @@ show_line (abfd, section, addr_offset) p->next = print_files; print_files = p; - if (file_start_context) - l = 0; - else - l = line - SHOW_PRECEDING_CONTEXT_LINES; + if (file_start_context) + l = 0; + else + l = line - SHOW_PRECEDING_CONTEXT_LINES; if (l < 0) l = 0; skip_to_line (p, l, false); @@ -1165,35 +1095,20 @@ typedef struct /* sprintf to a "stream" */ static int -#ifdef ANSI_PROTOTYPES -objdump_sprintf (SFILE *f, const char *format, ...) -#else -objdump_sprintf (va_alist) - va_dcl -#endif +objdump_sprintf VPARAMS ((SFILE *f, const char *format, ...)) { -#ifndef ANSI_PROTOTYPES - SFILE *f; - const char *format; -#endif char *buf; - va_list args; size_t n; -#ifdef ANSI_PROTOTYPES - va_start (args, format); -#else - va_start (args); - f = va_arg (args, SFILE *); - format = va_arg (args, const char *); -#endif + VA_OPEN (args, format); + VA_FIXEDARG (args, SFILE *, f); + VA_FIXEDARG (args, const char *, format); vasprintf (&buf, format, args); - va_end (args); - if (buf == NULL) { + va_end (args); fatal (_("Out of virtual memory")); } @@ -1215,13 +1130,16 @@ objdump_sprintf (va_alist) free (buf); + VA_CLOSE (args); return n; } /* The number of zeroes we want to see before we start skipping them. The number is arbitrarily chosen. */ +#ifndef SKIP_ZEROES #define SKIP_ZEROES (8) +#endif /* The number of zeroes to skip at the end of a section. If the number of zeroes at the end is between SKIP_ZEROES_AT_END and @@ -1230,13 +1148,15 @@ objdump_sprintf (va_alist) attempt to avoid disassembling zeroes inserted by section alignment. */ +#ifndef SKIP_ZEROES_AT_END #define SKIP_ZEROES_AT_END (3) +#endif /* Disassemble some data in memory between given values. */ static void -disassemble_bytes (info, disassemble_fn, insns, data, - start_offset, stop_offset, relppp, +disassemble_bytes (info, disassemble_fn, insns, data, + start_offset, stop_offset, relppp, relppend) struct disassemble_info *info; disassembler_ftype disassemble_fn; @@ -1273,8 +1193,10 @@ disassemble_bytes (info, disassemble_fn, insns, data, char buf[30]; char *s; - sprintf_vma (buf, section->vma + - bfd_section_size (section->owner, section) / opb); + bfd_sprintf_vma + (aux->abfd, buf, + (section->vma + + bfd_section_size (section->owner, section) / opb)); s = buf; while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0' && s[4] == '0') @@ -1303,8 +1225,8 @@ disassemble_bytes (info, disassemble_fn, insns, data, && (info->insn_info_valid == 0 || info->branch_delay_insns == 0) && (z - addr_offset * opb >= SKIP_ZEROES - || (z == stop_offset * opb && - z - addr_offset * opb < SKIP_ZEROES_AT_END))) + || (z == stop_offset * opb && + z - addr_offset * opb < SKIP_ZEROES_AT_END))) { printf ("\t...\n"); @@ -1327,13 +1249,16 @@ disassemble_bytes (info, disassemble_fn, insns, data, done_dot = false; if (with_line_numbers || with_source_code) - show_line (aux->abfd, section, addr_offset); + /* The line number tables will refer to unadjusted + section VMAs, so we must undo any VMA modifications + when calling show_line. */ + show_line (aux->abfd, section, addr_offset - adjust_section_vma); if (! prefix_addresses) { char *s; - sprintf_vma (buf, section->vma + addr_offset); + bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset); for (s = buf + skip_addr_chars; *s == '0'; s++) *s = ' '; if (*s == '\0') @@ -1392,7 +1317,7 @@ disassemble_bytes (info, disassemble_fn, insns, data, for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j) { - if (isprint (data[j])) + if (ISPRINT (data[j])) buf[j - addr_offset * opb] = data[j]; else buf[j - addr_offset * opb] = '.'; @@ -1470,7 +1395,7 @@ disassemble_bytes (info, disassemble_fn, insns, data, putchar ('\n'); j = addr_offset * opb + pb; - sprintf_vma (buf, section->vma + j / opb); + bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb); for (s = buf + skip_addr_chars; *s == '0'; s++) *s = ' '; if (*s == '\0') @@ -1507,8 +1432,8 @@ disassemble_bytes (info, disassemble_fn, insns, data, } if ((section->flags & SEC_RELOC) != 0 -#ifndef DISASSEMBLER_NEEDS_RELOCS - && dump_reloc_info +#ifndef DISASSEMBLER_NEEDS_RELOCS + && dump_reloc_info #endif ) { @@ -1644,7 +1569,7 @@ disassemble_data (abfd) disasm_info.mach = bfd_get_mach (abfd); disasm_info.disassembler_options = disassembler_options; disasm_info.octets_per_byte = opb; - + if (bfd_big_endian (abfd)) disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG; else if (bfd_little_endian (abfd)) @@ -1676,10 +1601,10 @@ disassemble_data (abfd) continue; if ((section->flags & SEC_RELOC) != 0 -#ifndef DISASSEMBLER_NEEDS_RELOCS +#ifndef DISASSEMBLER_NEEDS_RELOCS && dump_reloc_info #endif - ) + ) { long relsize; @@ -1727,6 +1652,7 @@ disassemble_data (abfd) disasm_info.buffer = data; disasm_info.buffer_vma = section->vma; disasm_info.buffer_length = datasize; + disasm_info.section = section; if (start_address == (bfd_vma) -1 || start_address < disasm_info.buffer_vma) addr_offset = 0; @@ -1752,7 +1678,7 @@ disassemble_data (abfd) asymbol *nextsym; unsigned long nextstop_offset; boolean insns; - + if (sym != NULL && bfd_asymbol_value (sym) <= section->vma + addr_offset) { int x; @@ -1777,7 +1703,7 @@ disassemble_data (abfd) false); printf (":\n"); } - + if (sym != NULL && bfd_asymbol_value (sym) > section->vma + addr_offset) nextsym = sym; else if (sym == NULL) @@ -1798,7 +1724,7 @@ disassemble_data (abfd) else nextsym = sorted_syms[place]; } - + if (sym != NULL && bfd_asymbol_value (sym) > section->vma + addr_offset) { nextstop_offset = bfd_asymbol_value (sym) - section->vma; @@ -1813,7 +1739,7 @@ disassemble_data (abfd) if (nextstop_offset > stop_offset) nextstop_offset = stop_offset; } - + /* If a symbol is explicitly marked as being an object rather than a function, just dump the bytes without disassembling them. */ @@ -1829,14 +1755,14 @@ disassemble_data (abfd) insns = true; else insns = false; - - disassemble_bytes (&disasm_info, disassemble_fn, insns, data, - addr_offset, nextstop_offset, &relpp, relppend); - + + disassemble_bytes (&disasm_info, disassemble_fn, insns, data, + addr_offset, nextstop_offset, &relpp, relppend); + addr_offset = nextstop_offset; sym = nextsym; } - + free (data); if (relbuf != NULL) free (relbuf); @@ -1899,13 +1825,13 @@ read_section_stabs (abfd, stabsect_name, strsect_name) exit_status = 1; return false; } - + stab_size = bfd_section_size (abfd, stabsect); stabstr_size = bfd_section_size (abfd, stabstrsect); stabs = (bfd_byte *) xmalloc (stab_size); strtab = (char *) xmalloc (stabstr_size); - + if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size)) { non_fatal (_("Reading %s section of %s failed: %s"), @@ -1987,7 +1913,7 @@ print_section_stabs (abfd, stabsect_name, strsect_name) printf ("\n%-6d ", i); /* Either print the stab name, or, if unnamed, print its number - again (makes consistent formatting for tools like awk). */ + again (makes consistent formatting for tools like awk). */ name = bfd_get_stab_name (type); if (name != NULL) printf ("%-6s", name); @@ -1996,7 +1922,7 @@ print_section_stabs (abfd, stabsect_name, strsect_name) else printf ("%-6d", type); printf (" %-6d %-6d ", other, desc); - printf_vma (value); + bfd_printf_vma (abfd, value); printf (" %-6lu", strx); /* Symbols with type == 0 (N_UNDF) specify the length of the @@ -2045,7 +1971,7 @@ dump_section_stabs (abfd, stabsect_name, strsect_name) match or a section followed by a number. */ if (strncmp (stabsect_name, s->name, len) == 0 && (s->name[len] == '\000' - || isdigit ((unsigned char) s->name[len]))) + || ISDIGIT (s->name[len]))) { if (read_section_stabs (abfd, s->name, strsect_name)) { @@ -2079,8 +2005,9 @@ dump_bfd_header (abfd) PF (WP_TEXT, "WP_TEXT"); PF (D_PAGED, "D_PAGED"); PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE"); + PF (HAS_LOAD_PAGE, "HAS_LOAD_PAGE"); printf (_("\nstart address 0x")); - printf_vma (abfd->start_address); + bfd_printf_vma (abfd, abfd->start_address); printf ("\n"); } @@ -2111,8 +2038,6 @@ dump_bfd (abfd) } } - printf (_("\n%s: file format %s\n"), bfd_get_filename (abfd), - abfd->xvec->name); if (dump_ar_hdrs) print_arelt_descr (stdout, abfd, true); if (dump_file_header) @@ -2122,14 +2047,12 @@ dump_bfd (abfd) putchar ('\n'); if (dump_section_headers) dump_headers (abfd); + if (dump_symtab || dump_reloc_info || disassemble || dump_debugging) - { - syms = slurp_symtab (abfd); - } + syms = slurp_symtab (abfd); if (dump_dynamic_symtab || dump_dynamic_reloc_info) - { - dynsyms = slurp_dynamic_symtab (abfd); - } + dynsyms = slurp_dynamic_symtab (abfd); + if (dump_symtab) dump_symbols (abfd, false); if (dump_dynamic_symtab) @@ -2159,11 +2082,13 @@ dump_bfd (abfd) } } } + if (syms) { free (syms); syms = NULL; } + if (dynsyms) { free (dynsyms); @@ -2308,15 +2233,15 @@ dump_data (abfd) if (stop_offset > bfd_section_size (abfd, section) / opb) stop_offset = bfd_section_size (abfd, section) / opb; } - for (addr_offset = start_offset; - addr_offset < stop_offset; addr_offset += onaline) + for (addr_offset = start_offset; + addr_offset < stop_offset; addr_offset += onaline) { bfd_size_type j; - printf (" %04lx ", (unsigned long int) - (addr_offset + section->vma)); - for (j = addr_offset * opb; - j < addr_offset * opb + onaline; j++) + printf (" %04lx ", (unsigned long int) + (addr_offset + section->vma)); + for (j = addr_offset * opb; + j < addr_offset * opb + onaline; j++) { if (j < stop_offset * opb) printf ("%02x", (unsigned) (data[j])); @@ -2332,7 +2257,7 @@ dump_data (abfd) if (j >= stop_offset * opb) printf (" "); else - printf ("%c", isprint (data[j]) ? data[j] : '.'); + printf ("%c", ISPRINT (data[j]) ? data[j] : '.'); } putchar ('\n'); } @@ -2356,19 +2281,18 @@ dump_symbols (abfd, dynamic) { current = dynsyms; max = dynsymcount; - if (max == 0) - return; printf ("DYNAMIC SYMBOL TABLE:\n"); } else { current = syms; max = symcount; - if (max == 0) - return; printf ("SYMBOL TABLE:\n"); } + if (max == 0) + printf (_("no symbols\n")); + for (count = 0; count < max; count++) { if (*current) @@ -2380,24 +2304,16 @@ dump_symbols (abfd, dynamic) const char *name; char *alloc; - name = bfd_asymbol_name (*current); + name = (*current)->name; alloc = NULL; if (do_demangle && name != NULL && *name != '\0') { - const char *n; - /* If we want to demangle the name, we demangle it here, and temporarily clobber it while calling bfd_print_symbol. FIXME: This is a gross hack. */ - n = name; - if (bfd_get_symbol_leading_char (cur_bfd) == *n) - ++n; - alloc = cplus_demangle (n, DMGL_ANSI | DMGL_PARAMS); - if (alloc != NULL) - (*current)->name = alloc; - else - (*current)->name = n; + alloc = demangle (cur_bfd, name); + (*current)->name = alloc; } bfd_print_symbol (cur_bfd, stdout, *current, @@ -2529,7 +2445,7 @@ dump_reloc_set (abfd, sec, relpp, relcount) if (width == 0) { char buf[30]; - sprintf_vma (buf, (bfd_vma) -1); + bfd_sprintf_vma (abfd, buf, (bfd_vma) -1); width = strlen (buf) - 7; } printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, ""); @@ -2597,7 +2513,7 @@ dump_reloc_set (abfd, sec, relpp, relcount) } if (sym_name) { - printf_vma (q->address); + bfd_printf_vma (abfd, q->address); if (q->howto->name) printf (" %-16s ", q->howto->name); else @@ -2607,9 +2523,9 @@ dump_reloc_set (abfd, sec, relpp, relcount) } else { - if (section_name == (CONST char *) NULL) + if (section_name == (const char *) NULL) section_name = "*unknown*"; - printf_vma (q->address); + bfd_printf_vma (abfd, q->address); printf (" %-16s [%s]", q->howto->name, section_name); @@ -2617,7 +2533,7 @@ dump_reloc_set (abfd, sec, relpp, relcount) if (q->addend) { printf ("+0x"); - printf_vma (q->addend); + bfd_printf_vma (abfd, q->addend); } printf ("\n"); } @@ -2644,14 +2560,14 @@ endian_string (endian) static void display_target_list () { - extern bfd_target *bfd_target_vector[]; + extern const bfd_target *const *bfd_target_vector; char *dummy_name; int t; dummy_name = make_temp_file (NULL); for (t = 0; bfd_target_vector[t]; t++) { - bfd_target *p = bfd_target_vector[t]; + const bfd_target *p = bfd_target_vector[t]; bfd *abfd = bfd_openw (dummy_name, p->name); int a; @@ -2692,7 +2608,7 @@ display_info_table (first, last) int first; int last; { - extern bfd_target *bfd_target_vector[]; + extern const bfd_target *const *bfd_target_vector; int t, a; char *dummy_name; @@ -2710,7 +2626,7 @@ display_info_table (first, last) bfd_printable_arch_mach (a, 0)); for (t = first; t < last && bfd_target_vector[t]; t++) { - bfd_target *p = bfd_target_vector[t]; + const bfd_target *p = bfd_target_vector[t]; boolean ok = true; bfd *abfd = bfd_openw (dummy_name, p->name); @@ -2761,7 +2677,7 @@ static void display_target_tables () { int t, columns; - extern bfd_target *bfd_target_vector[]; + extern const bfd_target *const *bfd_target_vector; char *colum; columns = 0; @@ -2795,11 +2711,13 @@ display_target_tables () static void display_info () { - printf (_("BFD header file version %s\n"), BFD_VERSION); + printf (_("BFD header file version %s\n"), BFD_VERSION_STRING); display_target_list (); display_target_tables (); } +int main PARAMS ((int, char **)); + int main (argc, argv) int argc; @@ -2811,6 +2729,9 @@ main (argc, argv) #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) setlocale (LC_MESSAGES, ""); +#endif +#if defined (HAVE_SETLOCALE) + setlocale (LC_CTYPE, ""); #endif bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); @@ -2823,14 +2744,14 @@ main (argc, argv) bfd_init (); set_default_bfd_target (); - while ((c = getopt_long (argc, argv, "pib:m:M:VCdDlfahHrRtTxsSj:wE:zgG", + while ((c = getopt_long (argc, argv, "pib:m:M:VvCdDlfaHhrRtTxsSj:wE:zgG", long_options, (int *) 0)) != EOF) { switch (c) { case 0: - break; /* we've been given a long option */ + break; /* We've been given a long option. */ case 'm': machine = optarg; break; @@ -2851,14 +2772,14 @@ main (argc, argv) if (optarg != NULL) { enum demangling_styles style; - + style = cplus_demangle_name_to_style (optarg); - if (style == unknown_demangling) + if (style == unknown_demangling) fatal (_("unknown demangling style `%s'"), optarg); - + cplus_demangle_set_style (style); - } + } break; case 'w': wide_output = true; @@ -2894,7 +2815,7 @@ main (argc, argv) usage (stderr, 1); } break; - + case 'f': dump_file_header = true; seenflag = true; @@ -2972,11 +2893,12 @@ main (argc, argv) case 'H': usage (stdout, 0); seenflag = true; + case 'v': case 'V': show_version = true; seenflag = true; break; - + default: usage (stderr, 1); }