How to get file descriptor from abfd?

Paul Pluzhnikov ppluzhnikov@google.com
Sun May 31 17:56:00 GMT 2009


Greetings,

Currently GDB allocates memory and does a bfd_read() on dwarf debug sections.

This causes GDB to be significantly slower on low-memory machines than
it has to be, and I have a patch to fix this by directly mmap()ing the
debug sections instead:
http://sourceware.org/ml/gdb-patches/2009-05/txt00023.txt

In that patch, I do:

+      caddr_t retbuf = mmap (0, map_length, PROT_READ, MAP_PRIVATE,
+			     fileno ((FILE *)abfd->iostream),
+			     pg_offset);

and this cast of abfd->iostream has been flagged as possibly un-kosher.

What is the proper way to get access to the underlying file descriptor
for a given abfd (if there is one)?
If there isn't a way, should there be?

I would have used bfd_get_file_window(), but it's only compiled in
when --use-mmap was given to bfd/configure.

Is there a way to turn that on for GDB?

The  bfd_get_file_window() performs above cast, after checking for:

      (abfd->flags & BFD_IN_MEMORY) == 0)

and later

      if (abfd->iostream == NULL
	  && (abfd->iovec == NULL
	      || abfd->iovec->bseek (abfd, offset, SEEK_SET) != 0))

The last 3 conditions can not be true in gdb/dwarf2read.c because we just
performed bfd_seek and bfd_bread on abfd.

Looks like BFD_IN_MEMORY could be set though.

Is it ok to do this:

  if ((abfd->flags & BFD_IN_MEMORY) == 0) ...

in gdb/dwarf2read.c?

Thanks,
-- 
Paul Pluzhnikov



More information about the Gdb-patches mailing list