aboutsummaryrefslogtreecommitdiff
path: root/libopagent/bfddefines.c
blob: 0cd269bc44251966d5ceaa8d8d57aa9c8c43993d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * @file bfddefines.c
 * Write out defines for BFD arch and mach of the given binary
 *
 * @remark Copyright 2007 OProfile authors
 * @remark Read the file COPYING
 *
 * @author Jens Wilke
 *
 * Copyright IBM Corporation 2007
 *
 */

#include <stdio.h>
#include <bfd.h>

int main(int argc, char ** args)
{
	bfd * bfd;
	bfd_boolean r;

	bfd_init();
	bfd = bfd_openr(args[1], NULL);
	if (bfd == NULL) {
		bfd_perror("bfd_open");
		return 1;
	}
	r = bfd_check_format(bfd, bfd_object);
	if (!r) {
		bfd_perror("bfd_get_arch");
		return 1;
	}
	printf("/* automatically generated by bfddefines, do not edit*/\n");
	printf("#define BFD_TARGET_NAME \"%s\"\n", bfd->xvec->name);
	printf("#define BFD_ARCH %i\n", bfd_get_arch(bfd));
	printf("#define BFD_MACH %lu\n", bfd_get_mach(bfd));
	printf("#define BFD_PRINTABLE_NAME \"%s\"\n", bfd_printable_name(bfd));

	return 0;
}