From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31684 invoked by alias); 31 May 2009 18:12:43 -0000 Received: (qmail 31671 invoked by uid 22791); 31 May 2009 18:12:43 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-ew0-f211.google.com (HELO mail-ew0-f211.google.com) (209.85.219.211) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 31 May 2009 18:12:38 +0000 Received: by ewy7 with SMTP id 7so7421517ewy.24 for ; Sun, 31 May 2009 11:12:35 -0700 (PDT) Received: by 10.210.61.2 with SMTP id j2mr3047064eba.2.1243793555456; Sun, 31 May 2009 11:12:35 -0700 (PDT) Received: from ?192.168.2.99? (cpc2-cmbg8-0-0-cust61.cmbg.cable.ntl.com [82.6.108.62]) by mx.google.com with ESMTPS id 5sm286969eyh.30.2009.05.31.11.12.34 (version=SSLv3 cipher=RC4-MD5); Sun, 31 May 2009 11:12:34 -0700 (PDT) Message-ID: <4A22CB56.3070704@gmail.com> Date: Sun, 31 May 2009 18:12:00 -0000 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Paul Pluzhnikov CC: binutils@sourceware.org, Tom Tromey , gdb-patches ml Subject: Re: How to get file descriptor from abfd? References: <8ac60eac0905311056l3b8edf98rc6abfe28853e0b6d@mail.gmail.com> In-Reply-To: <8ac60eac0905311056l3b8edf98rc6abfe28853e0b6d@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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/msg00665.txt.bz2 Paul Pluzhnikov wrote: > 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? It's a bad idea, because anything you do to that FILE* might confuse the underlying bfd_iovec stream. The cleanest design would be to add an mmap member function to bfd_iovec. > 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? Just configure with it. It will be passed to the included bfd/ configure. > Is it ok to do this: > > if ((abfd->flags & BFD_IN_MEMORY) == 0) ... > > in gdb/dwarf2read.c? Won't be necessary if you do it the iovec way, there will just be a stub implementation of 'bmmap()' for in-memory iovecs and a real one (conditioned on HAVE_MMAP) for file-based iovecs. Then gdb can call the bfd_mmap wrapper function speculatively and just fall back to the old way of doing it if that returns an error code. cheers, DaveK