- *filename_ptr = NULL;
- if (! do_line)
- *functionname_ptr = NULL;
- *linenumber_ptr = 0;
-
- if (! *pinfo)
- {
- bfd *debug_bfd;
- bfd_size_type total_size;
- asection *msec;
-
- *pinfo = stash;
-
- msec = find_debug_info (abfd, NULL);
- if (msec == NULL)
- {
- char * debug_filename = bfd_follow_gnu_debuglink (abfd, DEBUGDIR);
-
- if (debug_filename == NULL)
- /* No dwarf2 info, and no gnu_debuglink to follow.
- Note that at this point the stash has been allocated, but
- contains zeros. This lets future calls to this function
- fail more quickly. */
- goto done;
-
- if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
- || ! bfd_check_format (debug_bfd, bfd_object)
- || (msec = find_debug_info (debug_bfd, NULL)) == NULL)
- {
- if (debug_bfd)
- bfd_close (debug_bfd);
- /* FIXME: Should we report our failure to follow the debuglink ? */
- free (debug_filename);
- goto done;
- }
- }
- else
- debug_bfd = abfd;
-
- /* There can be more than one DWARF2 info section in a BFD these
- days. First handle the easy case when there's only one. If
- there's more than one, try case two: none of the sections is
- compressed. In that case, read them all in and produce one
- large stash. We do this in two passes - in the first pass we
- just accumulate the section sizes, and in the second pass we
- read in the section's contents. (The allows us to avoid
- reallocing the data as we add sections to the stash.) If
- some or all sections are compressed, then do things the slow
- way, with a bunch of reallocs. */
-
- if (! find_debug_info (debug_bfd, msec))
- {
- /* Case 1: only one info section. */
- total_size = msec->size;
- if (! read_section (debug_bfd, ".debug_info", ".zdebug_info",
- symbols, 0,
- &stash->info_ptr_memory, &total_size))
- goto done;
- }
- else
- {
- int all_uncompressed = 1;
- for (total_size = 0; msec; msec = find_debug_info (debug_bfd, msec))
- {
- total_size += msec->size;
- if (strcmp (msec->name, DWARF2_COMPRESSED_DEBUG_INFO) == 0)
- all_uncompressed = 0;
- }
- if (all_uncompressed)
- {
- /* Case 2: multiple sections, but none is compressed. */
- stash->info_ptr_memory = bfd_malloc (total_size);
- if (stash->info_ptr_memory == NULL)
- goto done;
-
- total_size = 0;
- for (msec = find_debug_info (debug_bfd, NULL);
- msec;
- msec = find_debug_info (debug_bfd, msec))
- {
- bfd_size_type size;
-
- size = msec->size;
- if (size == 0)
- continue;
-
- if (!(bfd_simple_get_relocated_section_contents
- (debug_bfd, msec, stash->info_ptr_memory + total_size,
- symbols)))
- goto done;
-
- total_size += size;
- }
- }
- else
- {
- /* Case 3: multiple sections, some or all compressed. */
- stash->info_ptr_memory = NULL;
- total_size = 0;
- for (msec = find_debug_info (debug_bfd, NULL);
- msec;
- msec = find_debug_info (debug_bfd, msec))
- {
- bfd_size_type size = msec->size;
- bfd_byte* buffer;
-
- if (size == 0)
- continue;
-
- buffer = (bfd_simple_get_relocated_section_contents
- (debug_bfd, msec, NULL, symbols));
- if (! buffer)
- goto done;
-
- if (strcmp (msec->name, DWARF2_COMPRESSED_DEBUG_INFO) == 0)
- {
- if (! bfd_uncompress_section_contents (&buffer, &size))
- {
- free (buffer);
- goto done;
- }
- }
- stash->info_ptr_memory = bfd_realloc (stash->info_ptr_memory,
- total_size + size);
- memcpy (stash->info_ptr_memory + total_size, buffer, size);
- free (buffer);
- total_size += size;
- }
- }
- }
-
- stash->info_ptr = stash->info_ptr_memory;
- stash->info_ptr_end = stash->info_ptr + total_size;
- stash->sec = find_debug_info (debug_bfd, NULL);
- stash->sec_info_ptr = stash->info_ptr;
- stash->syms = symbols;
- stash->bfd = debug_bfd;
- }