+static int
+load_specific_debug_section (enum dwarf_section_display_enum debug,
+ asection *sec, void *file)
+{
+ struct dwarf_section *section = &debug_displays [debug].section;
+ bfd *abfd = (bfd *) file;
+ bfd_boolean ret;
+
+ /* If it is already loaded, do nothing. */
+ if (section->start != NULL)
+ return 1;
+
+ section->address = 0;
+ section->size = bfd_get_section_size (sec);
+ section->start = NULL;
+ ret = bfd_get_full_section_contents (abfd, sec, §ion->start);
+
+ if (! ret)
+ {
+ free_debug_section (debug);
+ printf (_("\nCan't get contents for section '%s'.\n"),
+ section->name);
+ return 0;
+ }
+
+ if (is_relocatable && debug_displays [debug].relocate)
+ {
+ /* We want to relocate the data we've already read (and
+ decompressed), so we store a pointer to the data in
+ the bfd_section, and tell it that the contents are
+ already in memory. */
+ sec->contents = section->start;
+ sec->flags |= SEC_IN_MEMORY;
+ sec->size = section->size;
+
+ ret = bfd_simple_get_relocated_section_contents (abfd,
+ sec,
+ section->start,
+ syms) != NULL;
+
+ if (! ret)
+ {
+ free_debug_section (debug);
+ printf (_("\nCan't get contents for section '%s'.\n"),
+ section->name);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+int
+load_debug_section (enum dwarf_section_display_enum debug, void *file)
+{
+ struct dwarf_section *section = &debug_displays [debug].section;
+ bfd *abfd = (bfd *) file;
+ asection *sec;
+
+ /* If it is already loaded, do nothing. */
+ if (section->start != NULL)
+ return 1;
+
+ /* Locate the debug section. */
+ sec = bfd_get_section_by_name (abfd, section->uncompressed_name);
+ if (sec != NULL)
+ section->name = section->uncompressed_name;
+ else
+ {
+ sec = bfd_get_section_by_name (abfd, section->compressed_name);
+ if (sec != NULL)
+ section->name = section->compressed_name;
+ }
+ if (sec == NULL)
+ return 0;
+
+ return load_specific_debug_section (debug, sec, file);
+}
+
+void
+free_debug_section (enum dwarf_section_display_enum debug)
+{
+ struct dwarf_section *section = &debug_displays [debug].section;
+
+ if (section->start == NULL)
+ return;
+
+ free ((char *) section->start);
+ section->start = NULL;
+ section->address = 0;
+ section->size = 0;
+}
+
+static void
+dump_dwarf_section (bfd *abfd, asection *section,
+ void *arg ATTRIBUTE_UNUSED)
+{
+ const char *name = bfd_get_section_name (abfd, section);
+ const char *match;
+ int i;
+
+ if (CONST_STRNEQ (name, ".gnu.linkonce.wi."))
+ match = ".debug_info";
+ else
+ match = name;
+
+ for (i = 0; i < max; i++)
+ if ((strcmp (debug_displays [i].section.uncompressed_name, match) == 0
+ || strcmp (debug_displays [i].section.compressed_name, match) == 0)
+ && debug_displays [i].enabled != NULL
+ && *debug_displays [i].enabled)
+ {
+ struct dwarf_section *sec = &debug_displays [i].section;
+
+ if (strcmp (sec->uncompressed_name, match) == 0)
+ sec->name = sec->uncompressed_name;
+ else
+ sec->name = sec->compressed_name;
+ if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
+ section, abfd))
+ {
+ debug_displays [i].display (sec, abfd);
+
+ if (i != info && i != abbrev)
+ free_debug_section ((enum dwarf_section_display_enum) i);
+ }
+ break;
+ }
+}
+
+/* Dump the dwarf debugging information. */
+
+static void
+dump_dwarf (bfd *abfd)
+{
+ is_relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
+
+ eh_addr_size = bfd_arch_bits_per_address (abfd) / 8;
+
+ if (bfd_big_endian (abfd))
+ byte_get = byte_get_big_endian;
+ else if (bfd_little_endian (abfd))
+ byte_get = byte_get_little_endian;
+ else
+ abort ();
+
+ switch (bfd_get_arch (abfd))
+ {
+ case bfd_arch_i386:
+ switch (bfd_get_mach (abfd))
+ {
+ case bfd_mach_x86_64:
+ case bfd_mach_x86_64_intel_syntax:
+ init_dwarf_regnames_x86_64 ();
+ break;
+
+ default:
+ init_dwarf_regnames_i386 ();
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ bfd_map_over_sections (abfd, dump_dwarf_section, NULL);
+
+ free_debug_memory ();
+}
+\f