BFD question
Bloch, Jack
Jack.Bloch@icn.siemens.com
Mon May 17 19:50:00 GMT 2004
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.
More information about the Gdb
mailing list