25 #define unlikely(cond) (cond)
43 static void usage(
void)
45 fprintf(stderr,
"Usage: objdump -d a.out | awk -f distill.awk |"
46 " %s [-y|-n] [-v]\n",
prog);
47 fprintf(stderr,
"\t-y 64bit mode\n");
48 fprintf(stderr,
"\t-n 32bit mode\n");
49 fprintf(stderr,
"\t-v verbose mode\n");
53 static void malformed_line(
const char *
line,
int line_nr)
55 fprintf(stderr,
"%s: malformed line %d:\n%s", prog, line_nr, line);
62 fprintf(fp,
"%s.%s = {\n", indent, name);
63 fprintf(fp,
"%s\t.value = %d, bytes[] = {%x, %x, %x, %x},\n",
66 fprintf(fp,
"%s\t.got = %d, .nbytes = %d},\n", indent,
70 static void dump_insn(FILE *
fp,
struct insn *
insn)
72 fprintf(fp,
"Instruction = {\n");
82 fprintf(fp,
"\t.attr = %x, .opnd_bytes = %d, .addr_bytes = %d,\n",
84 fprintf(fp,
"\t.length = %d, .x86_64 = %d, .kaddr = %p}\n",
88 static void parse_args(
int argc,
char **argv)
92 while ((c = getopt(argc, argv,
"ynv")) != -1) {
111 int main(
int argc,
char **argv)
114 unsigned char insn_buf[16];
119 parse_args(argc, argv);
121 while (fgets(line,
BUFSIZE, stdin)) {
122 char copy[
BUFSIZE], *
s, *tab1, *tab2;
126 if (line[0] ==
'<') {
135 tab1 =
strchr(copy,
'\t');
137 malformed_line(line, insns);
142 malformed_line(line, insns);
145 if (
sscanf(s,
"%x", &b) == 1) {
146 insn_buf[nb++] = (
unsigned char) b;
156 fprintf(stderr,
"Warning: %s found difference at %s\n",
158 fprintf(stderr,
"Warning: %s", line);
159 fprintf(stderr,
"Warning: objdump says %d bytes, but "
160 "insn_get_length() says %d\n", nb,
163 dump_insn(stderr, &insn);
167 fprintf(stderr,
"Warning: decoded and checked %d"
168 " instructions with %d warnings\n", insns, warnings);
170 fprintf(stderr,
"Succeed: decoded and checked %d"
171 " instructions\n", insns);