X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=binutils%2Fobjdump.c;h=535e0cd7e7864da09d7e5c4abacbe6648b84f582;hb=aa67bccfe2f5f131c09c600a64301ac206f8ac27;hp=4b64bd6f81d378c57c5b715bf976993ef90ea6ed;hpb=20fe064957a97380f25cfee7cf0349041f89bfb4;p=binutils-gdb.git diff --git a/binutils/objdump.c b/binutils/objdump.c index 4b64bd6f81d..535e0cd7e78 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -20,10 +20,10 @@ 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 "getopt.h" +#include "safe-ctype.h" #include "dis-asm.h" #include "libiberty.h" #include "demangle.h" @@ -108,122 +108,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\ @@ -240,7 +180,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\ ")); @@ -268,6 +208,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); } @@ -343,10 +284,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 "); @@ -363,9 +304,6 @@ dump_section_header (abfd, section, ignored) 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"); @@ -378,6 +316,7 @@ 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"); if ((section->flags & SEC_LINK_ONCE) != 0) { @@ -667,8 +606,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 @@ -1166,35 +1107,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")); } @@ -1216,6 +1142,7 @@ objdump_sprintf (va_alist) free (buf); + VA_CLOSE (args); return n; } @@ -1278,8 +1205,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') @@ -1341,7 +1270,7 @@ disassemble_bytes (info, disassemble_fn, insns, data, { 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') @@ -1400,7 +1329,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] = '.'; @@ -1478,7 +1407,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') @@ -1735,6 +1664,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; @@ -2004,7 +1934,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 @@ -2053,7 +1983,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)) { @@ -2088,7 +2018,7 @@ dump_bfd_header (abfd) PF (D_PAGED, "D_PAGED"); PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE"); printf (_("\nstart address 0x")); - printf_vma (abfd->start_address); + bfd_printf_vma (abfd, abfd->start_address); printf ("\n"); } @@ -2340,7 +2270,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'); } @@ -2537,7 +2467,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, ""); @@ -2605,7 +2535,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 @@ -2617,7 +2547,7 @@ dump_reloc_set (abfd, sec, relpp, relcount) { 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); @@ -2625,7 +2555,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"); } @@ -2803,11 +2733,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; @@ -2819,6 +2751,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); @@ -2831,14 +2766,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; @@ -2859,12 +2794,12 @@ main (argc, argv) if (optarg != NULL) { enum demangling_styles style; - + style = cplus_demangle_name_to_style (optarg); if (style == unknown_demangling) fatal (_("unknown demangling style `%s'"), optarg); - + cplus_demangle_set_style (style); } break; @@ -2902,7 +2837,7 @@ main (argc, argv) usage (stderr, 1); } break; - + case 'f': dump_file_header = true; seenflag = true; @@ -2980,6 +2915,7 @@ main (argc, argv) case 'H': usage (stdout, 0); seenflag = true; + case 'v': case 'V': show_version = true; seenflag = true;