+static void
+dump_relocs_in_section (bfd *abfd,
+ asection *section,
+ void *dummy ATTRIBUTE_UNUSED)
+{
+ arelent **relpp;
+ long relcount;
+ long relsize;
+
+ if ( bfd_is_abs_section (section)
+ || bfd_is_und_section (section)
+ || bfd_is_com_section (section)
+ || (! process_section_p (section))
+ || ((section->flags & SEC_RELOC) == 0))
+ return;
+
+ relsize = bfd_get_reloc_upper_bound (abfd, section);
+ if (relsize < 0)
+ bfd_fatal (bfd_get_filename (abfd));
+
+ printf ("RELOCATION RECORDS FOR [%s]:", section->name);
+
+ if (relsize == 0)
+ {
+ printf (" (none)\n\n");
+ return;
+ }
+
+ relpp = xmalloc (relsize);
+ relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms);
+
+ if (relcount < 0)
+ bfd_fatal (bfd_get_filename (abfd));
+ else if (relcount == 0)
+ printf (" (none)\n\n");
+ else
+ {
+ printf ("\n");
+ dump_reloc_set (abfd, section, relpp, relcount);
+ printf ("\n\n");
+ }
+ free (relpp);
+}
+
+static void
+dump_relocs (bfd *abfd)
+{
+ bfd_map_over_sections (abfd, dump_relocs_in_section, NULL);
+}
+
+static void
+dump_dynamic_relocs (bfd *abfd)
+{
+ long relsize;
+ arelent **relpp;
+ long relcount;
+
+ relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
+ if (relsize < 0)
+ bfd_fatal (bfd_get_filename (abfd));
+
+ printf ("DYNAMIC RELOCATION RECORDS");
+
+ if (relsize == 0)
+ printf (" (none)\n\n");
+ else
+ {
+ relpp = xmalloc (relsize);
+ relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
+
+ if (relcount < 0)
+ bfd_fatal (bfd_get_filename (abfd));
+ else if (relcount == 0)
+ printf (" (none)\n\n");
+ else
+ {
+ printf ("\n");
+ dump_reloc_set (abfd, NULL, relpp, relcount);
+ printf ("\n\n");
+ }
+ free (relpp);
+ }
+}
+
+/* Creates a table of paths, to search for source files. */
+
+static void
+add_include_path (const char *path)
+{
+ if (path[0] == 0)
+ return;
+ include_path_count++;
+ include_paths = xrealloc (include_paths,
+ include_path_count * sizeof (*include_paths));
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ if (path[1] == ':' && path[2] == 0)
+ path = concat (path, ".", (const char *) 0);
+#endif
+ include_paths[include_path_count - 1] = path;
+}
+
+static void
+adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *section,
+ void *arg)
+{
+ if ((section->flags & SEC_DEBUGGING) == 0)
+ {
+ bfd_boolean *has_reloc_p = (bfd_boolean *) arg;
+ section->vma += adjust_section_vma;
+ if (*has_reloc_p)
+ section->lma += adjust_section_vma;
+ }
+}
+
+/* Dump selected contents of ABFD. */
+
+static void
+dump_bfd (bfd *abfd)
+{
+ /* If we are adjusting section VMA's, change them all now. Changing
+ the BFD information is a hack. However, we must do it, or
+ bfd_find_nearest_line will not do the right thing. */
+ if (adjust_section_vma != 0)
+ {
+ bfd_boolean has_reloc = (abfd->flags & HAS_RELOC);
+ bfd_map_over_sections (abfd, adjust_addresses, &has_reloc);
+ }
+
+ if (! dump_debugging_tags)
+ 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)
+ dump_bfd_header (abfd);
+ if (dump_private_headers)
+ dump_bfd_private_header (abfd);
+ if (! dump_debugging_tags)
+ putchar ('\n');
+ if (dump_section_headers)
+ dump_headers (abfd);
+
+ if (dump_symtab
+ || dump_reloc_info
+ || disassemble
+ || dump_debugging
+ || dump_dwarf_section_info)
+ syms = slurp_symtab (abfd);
+ if (dump_dynamic_symtab || dump_dynamic_reloc_info
+ || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0))
+ dynsyms = slurp_dynamic_symtab (abfd);
+ if (disassemble)
+ {
+ synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms,
+ dynsymcount, dynsyms, &synthsyms);
+ if (synthcount < 0)
+ synthcount = 0;
+ }
+
+ if (dump_symtab)
+ dump_symbols (abfd, FALSE);
+ if (dump_dynamic_symtab)
+ dump_symbols (abfd, TRUE);
+ if (dump_dwarf_section_info)
+ dump_dwarf (abfd);
+ if (dump_stab_section_info)
+ dump_stabs (abfd);
+ if (dump_reloc_info && ! disassemble)
+ dump_relocs (abfd);
+ if (dump_dynamic_reloc_info && ! disassemble)
+ dump_dynamic_relocs (abfd);
+ if (dump_section_contents)
+ dump_data (abfd);
+ if (disassemble)
+ disassemble_data (abfd);
+
+ if (dump_debugging)
+ {
+ void *dhandle;
+
+ dhandle = read_debugging_info (abfd, syms, symcount);
+ if (dhandle != NULL)
+ {
+ if (!print_debugging_info (stdout, dhandle, abfd, syms,
+ bfd_demangle,
+ dump_debugging_tags ? TRUE : FALSE))
+ {
+ non_fatal (_("%s: printing debugging information failed"),
+ bfd_get_filename (abfd));
+ exit_status = 1;
+ }
+ }
+ }
+
+ if (syms)
+ {
+ free (syms);
+ syms = NULL;
+ }
+
+ if (dynsyms)
+ {
+ free (dynsyms);
+ dynsyms = NULL;
+ }
+
+ if (synthsyms)
+ {
+ free (synthsyms);
+ synthsyms = NULL;
+ }
+
+ symcount = 0;
+ dynsymcount = 0;
+ synthcount = 0;
+}
+
+static void
+display_bfd (bfd *abfd)
+{
+ char **matching;
+
+ if (bfd_check_format_matches (abfd, bfd_object, &matching))
+ {
+ dump_bfd (abfd);
+ return;
+ }
+
+ if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
+ {
+ nonfatal (bfd_get_filename (abfd));
+ list_matching_formats (matching);
+ free (matching);
+ return;
+ }
+
+ if (bfd_get_error () != bfd_error_file_not_recognized)
+ {
+ nonfatal (bfd_get_filename (abfd));
+ return;
+ }
+
+ if (bfd_check_format_matches (abfd, bfd_core, &matching))
+ {
+ dump_bfd (abfd);
+ return;
+ }
+
+ nonfatal (bfd_get_filename (abfd));
+
+ if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
+ {
+ list_matching_formats (matching);
+ free (matching);
+ }
+}
+
+static void
+display_file (char *filename, char *target)
+{
+ bfd *file;
+ bfd *arfile = NULL;
+
+ if (get_file_size (filename) < 1)
+ {
+ exit_status = 1;
+ return;
+ }
+
+ file = bfd_openr (filename, target);
+ if (file == NULL)
+ {
+ nonfatal (filename);
+ return;
+ }
+
+ /* If the file is an archive, process all of its elements. */
+ if (bfd_check_format (file, bfd_archive))
+ {
+ bfd *last_arfile = NULL;
+
+ printf (_("In archive %s:\n"), bfd_get_filename (file));
+ for (;;)
+ {
+ bfd_set_error (bfd_error_no_error);
+
+ arfile = bfd_openr_next_archived_file (file, arfile);
+ if (arfile == NULL)
+ {
+ if (bfd_get_error () != bfd_error_no_more_archived_files)
+ nonfatal (bfd_get_filename (file));
+ break;
+ }
+
+ display_bfd (arfile);
+
+ if (last_arfile != NULL)
+ bfd_close (last_arfile);
+ last_arfile = arfile;
+ }
+
+ if (last_arfile != NULL)
+ bfd_close (last_arfile);
+ }
+ else
+ display_bfd (file);
+
+ bfd_close (file);
+}
+\f