Skip to content

Commit

Permalink
bpf: support hex. output from bpftool/objdump
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
  • Loading branch information
pchaigno committed Oct 10, 2019
1 parent 88a4917 commit 3141501
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/rouge/lexers/bpf.rb
Expand Up @@ -17,6 +17,17 @@ class BPF < RegexLexer
).join('|')

state :root do
# Line numbers and hexadecimal output from bpftool/objdump
rule %r/(\d+)(:)(\s+)(\(\h{2}\))/i do
groups Generic::Lineno, Punctuation, Text::Whitespace, Generic
end
rule %r/(\d+)(:)(\s+)((\h{2} ){8})/i do
groups Generic::Lineno, Punctuation, Text::Whitespace, Generic
end
rule %r/(\d+)(:)(\s+)/i do
groups Generic::Lineno, Punctuation, Text::Whitespace
end

# Calls to helpers
rule %r/(call)(\s+)(\d+)/i do
groups Keyword, Text::Whitespace, Literal::Number::Integer
Expand Down
29 changes: 29 additions & 0 deletions spec/visual/samples/bpf
Expand Up @@ -115,3 +115,32 @@ Llabel0 :
r9 = 1 // BPF_MOV | BPF_K
r9 = 0xffffffff // BPF_MOV | BPF_K
r10 s>>= 64 // BPF_ARSH | BPF_K

0: (bf) r6 = r1
1: (69) r7 = *(u16 *)(r6 +176)
2: (b4) w8 = 0
3: (55) if r7 != 0x8 goto pc+14
4: (bf) r1 = r6
5: (b4) w2 = 12
6: (bf) r3 = r10
7: (07) r3 += -4
8: (b4) w4 = 4
9: (85) call bpf_skb_load_bytes#7684912
10: (18) r1 = map[id:671]
12: (bf) r2 = r10
13: (07) r2 += -8
14: (62) *(u32 *)(r2 +0) = 32

xdp_prog1:
0: 61 12 04 00 00 00 00 00 r2 = *(u32 *)(r1 + 4)
1: 61 11 00 00 00 00 00 00 r1 = *(u32 *)(r1 + 0)
2: bf 13 00 00 00 00 00 00 r3 = r1
3: 07 03 00 00 0e 00 00 00 r3 += 14
4: 2d 23 36 00 00 00 00 00 if r3 > r2 goto +54 <LBB0_20>
5: 71 13 0c 00 00 00 00 00 r3 = *(u8 *)(r1 + 12)
6: 71 14 0d 00 00 00 00 00 r4 = *(u8 *)(r1 + 13)
7: 67 04 00 00 08 00 00 00 r4 <<= 8
8: 4f 34 00 00 00 00 00 00 r4 |= r3
9: 15 04 02 00 88 a8 00 00 if r4 == 43144 goto +2 <LBB0_3>
10: b7 03 00 00 0e 00 00 00 r3 = 14
11: 55 04 05 00 81 00 00 00 if r4 != 129 goto +5 <LBB0_5>

0 comments on commit 3141501

Please sign in to comment.