Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Bloch, Jack" <Jack.Bloch@icn.siemens.com>
To: "'gdb@sources.redhat.com'" <gdb@sources.redhat.com>
Subject: BFD question
Date: Mon, 17 May 2004 19:50:00 -0000	[thread overview]
Message-ID: <7A25937D23A1E64C8E93CB4A50509C2A0310F1A8@stca204a.bus.sc.rolm.com> (raw)

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.


             reply	other threads:[~2004-05-17 19:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-17 19:50 Bloch, Jack [this message]
2004-05-17 20:01 ` Ian Lance Taylor
2004-05-17 20:54 ` Bloch, Jack
2004-05-17 21:07   ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7A25937D23A1E64C8E93CB4A50509C2A0310F1A8@stca204a.bus.sc.rolm.com \
    --to=jack.bloch@icn.siemens.com \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox