From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15277 invoked by alias); 17 May 2004 19:50:22 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 15267 invoked from network); 17 May 2004 19:50:20 -0000 Received: from unknown (HELO mail.siemenscom.com) (12.146.131.10) by sourceware.org with SMTP; 17 May 2004 19:50:20 -0000 Received: from fdns2.rolm.com (localhost [127.0.0.1]) by mail.siemenscom.com (8.12.10/8.12.10) with ESMTP id i4HJoJAw011744 for ; Mon, 17 May 2004 12:50:19 -0700 Received: from stca200a.bus.sc.rolm.com (stca200a.bus.sc.rolm.com [165.218.68.180]) by fdns2.rolm.com (8.12.10/8.12.10) with ESMTP id i4HJoI0B029849 for ; Mon, 17 May 2004 12:50:19 -0700 (PDT) Received: by stca200a.bus.sc.rolm.com with Internet Mail Service (5.5.2657.72) id ; Mon, 17 May 2004 12:50:18 -0700 Message-ID: <7A25937D23A1E64C8E93CB4A50509C2A0310F1A8@stca204a.bus.sc.rolm.com> From: "Bloch, Jack" To: "'gdb@sources.redhat.com'" Subject: BFD question Date: Mon, 17 May 2004 19:50:00 -0000 MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2004-05/txt/msg00107.txt.bz2 Can anyone help. I am writing an application that needs to read symbols from an executable file. I am running a stock SuSE 2.4.19 Kernel. I have libbfd version 2.12.90.0.15. My code reads as follows : bfd *l_bfd = NULL; char *l_target = "elf32-i386"; const char *l_err = NULL; long l_storage = 0; long l_symnum = 0; long l_ndx = 0; int l_dyn = 0; int l_flags = 0; int l_access = (EXEC_P | HAS_SYMS); asymbol **l_symbol = NULL; if (!p_file) { /* invalid file name */ printf("INVALID FILE NAME FOR EXTRACT SYMBOLS !!!\n"); return(-1); /* set error indicator */ } printf("EXTRACTING SYMBOLS FOR FILE %s\n",p_file); /*****************/ /* open the file */ /*****************/ if ((l_bfd = bfd_openr(p_file,l_target)) == NULL) { /* unable to open file */ l_err = bfd_errmsg(bfd_get_error ()); /* read BFD error */ printf("ERROR %s OPENing FILE %s FOR SYMBOL EXTRACTION !!!\n",l_err,p_file); return(-1); /* set error indicator */ } /***********************************/ /* check the file format to ensure */ /* an executable file. */ /***********************************/ if (!bfd_check_format(l_bfd,bfd_object)) { /* not an executable file */ l_err = bfd_errmsg(bfd_get_error ()); /* read BFD error */ printf("BFD ERROR %s VALIDATING EXECUTABLE SYMBOL FORMAT ON %s\n",l_err,p_file); bfd_close(l_bfd); /* close file */ return(-1); /* set error indicator */ } /*****************************************************/ /* ensure that the given file has symbols associated */ /* with it. */ /*****************************************************/ l_flags = bfd_get_file_flags(l_bfd); if ((l_flags & l_access) == 0) { /* no symbols associated with this file */ printf("NO SYMBOLIC INFORMATION FOUND FOR %s !!!\n",p_file); return(-1); /* set error indicator */ } /******************************************************/ /* determine the amount of memory needed to store the */ /* program symbols. this can be static or dynamic */ /* storage. */ /******************************************************/ l_storage = bfd_get_symtab_upper_bound(l_bfd); if (l_storage == 0); { /* static failed so try dynamic */ printf("RETRIEVING STATIC STORAGE FAILED, TRYING DYNAMIC !!!\n"); l_storage = bfd_get_dynamic_symtab_upper_bound(l_bfd); if (l_storage == 0); { /* cannot retrieve dynamic storage size */ printf("FAILED TO RETRIEVE DYNAMIC STORAGE SIZE !!!\n"); return(-1); /* set eror indicator */ } } return(0); /* set success indicator */ The call to bfd_get_file_flags returns a 0. The file is indeed an elf32-i386 target. Please respond to jack.bloch@icn.siemens.com Thanks in advance.