2 # Usage: objdump -d a.out | awk -f distill.awk | ./test_get_len
3 # Distills the disassembly as follows:
4 # - Removes all lines except the disassembled instructions.
5 # - For instructions that exceed 1 line (7 bytes), crams all the hex bytes
7 # - Remove bad(or prefix only) instructions
13 bad_expr =
"(\\(bad\\)|^rex|^.byte|^rep(z|nz)$|^lock$|^es$|^cs$|^ss$|^ds$|^fs$|^gs$|^data(16|32)$|^addr(16|32|64))"
19 if (split($
0, field
, "\t") < 3) {
20 # This is a continuation of the same insn.
21 prev_hex = prev_hex field
[2]
23 # Skip bad instructions
24 if (match(prev_mnemonic
, bad_expr
))
26 # Split fwait from other f* instructions
27 if (match(prev_hex
, fwait_expr
) && prev_mnemonic
!= "fwait") {
28 printf "%s\t%s\n", prev_addr
, fwait_str
29 sub(fwait_expr
, "", prev_hex
)
32 printf "%s\t%s\t%s\n", prev_addr
, prev_hex
, prev_mnemonic
35 prev_mnemonic = field
[3]
41 printf "%s\t%s\t%s\n", prev_addr
, prev_hex
, prev_mnemonic