Home | History | Annotate | Download | only in libopagent
      1 /**
      2  * @file bfddefines.c
      3  * Write out defines for BFD arch and mach of the given binary
      4  *
      5  * @remark Copyright 2007 OProfile authors
      6  * @remark Read the file COPYING
      7  *
      8  * @author Jens Wilke
      9  *
     10  * Copyright IBM Corporation 2007
     11  *
     12  */
     13 
     14 #include <stdio.h>
     15 #include <bfd.h>
     16 
     17 int main(int argc, char ** args)
     18 {
     19 	bfd * bfd;
     20 	bfd_boolean r;
     21 
     22 	bfd_init();
     23 	bfd = bfd_openr(args[1], NULL);
     24 	if (bfd == NULL) {
     25 		bfd_perror("bfd_open");
     26 		return 1;
     27 	}
     28 	r = bfd_check_format(bfd, bfd_object);
     29 	if (!r) {
     30 		bfd_perror("bfd_get_arch");
     31 		return 1;
     32 	}
     33 	printf("/* automatically generated by bfddefines, do not edit*/\n");
     34 	printf("#define BFD_TARGET_NAME \"%s\"\n", bfd->xvec->name);
     35 	printf("#define BFD_ARCH %i\n", bfd_get_arch(bfd));
     36 	printf("#define BFD_MACH %lu\n", bfd_get_mach(bfd));
     37 	printf("#define BFD_PRINTABLE_NAME \"%s\"\n", bfd_printable_name(bfd));
     38 
     39 	return 0;
     40 }
     41