From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14714 invoked by alias); 31 May 2009 17:56:46 -0000 Received: (qmail 14697 invoked by uid 22791); 31 May 2009 17:56:45 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 31 May 2009 17:56:40 +0000 Received: from spaceape10.eur.corp.google.com (spaceape10.eur.corp.google.com [172.28.16.144]) by smtp-out.google.com with ESMTP id n4VHubP7023997; Sun, 31 May 2009 18:56:37 +0100 Received: from qw-out-1920.google.com (qwf5.prod.google.com [10.241.194.69]) by spaceape10.eur.corp.google.com with ESMTP id n4VHuZQK019815; Sun, 31 May 2009 10:56:35 -0700 Received: by qw-out-1920.google.com with SMTP id 5so3923818qwf.0 for ; Sun, 31 May 2009 10:56:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.110.16 with SMTP id l16mr1513506qcp.92.1243792594976; Sun, 31 May 2009 10:56:34 -0700 (PDT) Date: Sun, 31 May 2009 17:56:00 -0000 Message-ID: <8ac60eac0905311056l3b8edf98rc6abfe28853e0b6d@mail.gmail.com> Subject: How to get file descriptor from abfd? From: Paul Pluzhnikov To: binutils@sourceware.org Cc: Tom Tromey , gdb-patches ml Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-05/txt/msg00663.txt.bz2 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