Skip to content

Commit

Permalink
luajit: improve debuginfo decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
dlatchx committed Jun 21, 2023
1 parent eb819dd commit 64c11be
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 66 deletions.
25 changes: 21 additions & 4 deletions format/luajit/luajit.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ func LuaJITDecodeKNum(d *decode.D) any {
}
}

func LuaJITDecodeDebug(d *decode.D, debuglen uint64, numbc uint64) {
d.FieldStruct("debug", func(d *decode.D) {
d.FieldArray("lines", func(d *decode.D) {
for i := uint64(0); i < numbc; i++ {
d.FieldU8("value")
}
})

// TODO: find out more about how to decode these strings
d.FieldArray("anotations", func(d *decode.D) {
i := numbc
for i < debuglen {
str := d.FieldUTF8Null("value")
i += uint64(len(str) + 1)
}
})
})
}

func LuaJITDecodeProto(di *DumpInfo, d *decode.D) {
length := d.FieldULEB128("length")

Expand Down Expand Up @@ -327,10 +346,8 @@ func LuaJITDecodeProto(di *DumpInfo, d *decode.D) {
})

if !di.Strip {
d.FieldArray("debug", func(d *decode.D) {
for i := uint64(0); i < debuglen; i++ {
d.FieldU8("db")
}
d.LimitedFn(8*int64(debuglen), func(d *decode.D) {
LuaJITDecodeDebug(d, debuglen, numbc)
})
}
})
Expand Down
102 changes: 40 additions & 62 deletions format/luajit/testdata/simple.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,22 @@ $ fq dv simple.luac
0x030| d2 f9 ea| ...| [0]: 2973289 knum 0x3d-0x40.7 (4)
0x040|02 |. |
0x040| 81 80 90 9d 0c 8a a1 88 91 04 | .......... | [1]: 3.8793457897e+10 knum 0x41-0x4a.7 (10)
| | | debug[0:20]: 0x4b-0x5e.7 (20)
0x040| 01 | . | [0]: 1 db 0x4b-0x4b.7 (1)
0x040| 01 | . | [1]: 1 db 0x4c-0x4c.7 (1)
0x040| 01 | . | [2]: 1 db 0x4d-0x4d.7 (1)
0x040| 02 | . | [3]: 2 db 0x4e-0x4e.7 (1)
0x040| 02| .| [4]: 2 db 0x4f-0x4f.7 (1)
0x050|02 |. | [5]: 2 db 0x50-0x50.7 (1)
0x050| 02 | . | [6]: 2 db 0x51-0x51.7 (1)
0x050| 61 | a | [7]: 97 db 0x52-0x52.7 (1)
0x050| 00 | . | [8]: 0 db 0x53-0x53.7 (1)
0x050| 62 | b | [9]: 98 db 0x54-0x54.7 (1)
0x050| 00 | . | [10]: 0 db 0x55-0x55.7 (1)
0x050| 78 | x | [11]: 120 db 0x56-0x56.7 (1)
0x050| 00 | . | [12]: 0 db 0x57-0x57.7 (1)
0x050| 00 | . | [13]: 0 db 0x58-0x58.7 (1)
0x050| 08 | . | [14]: 8 db 0x59-0x59.7 (1)
0x050| 63 | c | [15]: 99 db 0x5a-0x5a.7 (1)
0x050| 00 | . | [16]: 0 db 0x5b-0x5b.7 (1)
0x050| 04 | . | [17]: 4 db 0x5c-0x5c.7 (1)
0x050| 04 | . | [18]: 4 db 0x5d-0x5d.7 (1)
0x050| 00 | . | [19]: 0 db 0x5e-0x5e.7 (1)
| | | debug{}: 0x4b-0x5e.7 (20)
| | | lines[0:7]: 0x4b-0x51.7 (7)
0x040| 01 | . | [0]: 1 value 0x4b-0x4b.7 (1)
0x040| 01 | . | [1]: 1 value 0x4c-0x4c.7 (1)
0x040| 01 | . | [2]: 1 value 0x4d-0x4d.7 (1)
0x040| 02 | . | [3]: 2 value 0x4e-0x4e.7 (1)
0x040| 02| .| [4]: 2 value 0x4f-0x4f.7 (1)
0x050|02 |. | [5]: 2 value 0x50-0x50.7 (1)
0x050| 02 | . | [6]: 2 value 0x51-0x51.7 (1)
| | | anotations[0:6]: 0x52-0x5e.7 (13)
0x050| 61 00 | a. | [0]: "a" value 0x52-0x53.7 (2)
0x050| 62 00 | b. | [1]: "b" value 0x54-0x55.7 (2)
0x050| 78 00 | x. | [2]: "x" value 0x56-0x57.7 (2)
0x050| 00 | . | [3]: "" value 0x58-0x58.7 (1)
0x050| 08 63 00 | .c. | [4]: "\bc" value 0x59-0x5b.7 (3)
0x050| 04 04 00 | ... | [5]: "\x04\x04" value 0x5c-0x5e.7 (3)
| | | [1]{}: proto 0x5f-0x181.7 (291)
0x050| a1| .| length: 289 0x5f-0x60.7 (2)
0x060|02 |. |
Expand Down Expand Up @@ -266,45 +261,28 @@ $ fq dv simple.luac
0x150| 03 | . | type: "int" (3) 0x154-0x154.7 (1)
0x150| fd ff ff ff 0f | ..... | value: 4294967293 0x155-0x159.7 (5)
| | | knum[0:0]: 0x15a-NA (0)
| | | debug[0:40]: 0x15a-0x181.7 (40)
0x150| 01 | . | [0]: 1 db 0x15a-0x15a.7 (1)
0x150| 13 | . | [1]: 19 db 0x15b-0x15b.7 (1)
0x150| 13 | . | [2]: 19 db 0x15c-0x15c.7 (1)
0x150| 15 | . | [3]: 21 db 0x15d-0x15d.7 (1)
0x150| 18 | . | [4]: 24 db 0x15e-0x15e.7 (1)
0x150| 19| .| [5]: 25 db 0x15f-0x15f.7 (1)
0x160|1e |. | [6]: 30 db 0x160-0x160.7 (1)
0x160| 20 | | [7]: 32 db 0x161-0x161.7 (1)
0x160| 21 | ! | [8]: 33 db 0x162-0x162.7 (1)
0x160| 21 | ! | [9]: 33 db 0x163-0x163.7 (1)
0x160| 21 | ! | [10]: 33 db 0x164-0x164.7 (1)
0x160| 21 | ! | [11]: 33 db 0x165-0x165.7 (1)
0x160| 21 | ! | [12]: 33 db 0x166-0x166.7 (1)
0x160| 21 | ! | [13]: 33 db 0x167-0x167.7 (1)
0x160| 73 | s | [14]: 115 db 0x168-0x168.7 (1)
0x160| 6f | o | [15]: 111 db 0x169-0x169.7 (1)
0x160| 6d | m | [16]: 109 db 0x16a-0x16a.7 (1)
0x160| 65 | e | [17]: 101 db 0x16b-0x16b.7 (1)
0x160| 74 | t | [18]: 116 db 0x16c-0x16c.7 (1)
0x160| 61 | a | [19]: 97 db 0x16d-0x16d.7 (1)
0x160| 62 | b | [20]: 98 db 0x16e-0x16e.7 (1)
0x160| 6c| l| [21]: 108 db 0x16f-0x16f.7 (1)
0x170|65 |e | [22]: 101 db 0x170-0x170.7 (1)
0x170| 00 | . | [23]: 0 db 0x171-0x171.7 (1)
0x170| 02 | . | [24]: 2 db 0x172-0x172.7 (1)
0x170| 0d | . | [25]: 13 db 0x173-0x173.7 (1)
0x170| 61 | a | [26]: 97 db 0x174-0x174.7 (1)
0x170| 00 | . | [27]: 0 db 0x175-0x175.7 (1)
0x170| 04 | . | [28]: 4 db 0x176-0x176.7 (1)
0x170| 09 | . | [29]: 9 db 0x177-0x177.7 (1)
0x170| 62 | b | [30]: 98 db 0x178-0x178.7 (1)
0x170| 00 | . | [31]: 0 db 0x179-0x179.7 (1)
0x170| 01 | . | [32]: 1 db 0x17a-0x17a.7 (1)
0x170| 08 | . | [33]: 8 db 0x17b-0x17b.7 (1)
0x170| 66 | f | [34]: 102 db 0x17c-0x17c.7 (1)
0x170| 31 | 1 | [35]: 49 db 0x17d-0x17d.7 (1)
0x170| 00 | . | [36]: 0 db 0x17e-0x17e.7 (1)
0x170| 01| .| [37]: 1 db 0x17f-0x17f.7 (1)
0x180|07 |. | [38]: 7 db 0x180-0x180.7 (1)
0x180| 00 | . | [39]: 0 db 0x181-0x181.7 (1)
| | | debug{}: 0x15a-0x181.7 (40)
| | | lines[0:14]: 0x15a-0x167.7 (14)
0x150| 01 | . | [0]: 1 value 0x15a-0x15a.7 (1)
0x150| 13 | . | [1]: 19 value 0x15b-0x15b.7 (1)
0x150| 13 | . | [2]: 19 value 0x15c-0x15c.7 (1)
0x150| 15 | . | [3]: 21 value 0x15d-0x15d.7 (1)
0x150| 18 | . | [4]: 24 value 0x15e-0x15e.7 (1)
0x150| 19| .| [5]: 25 value 0x15f-0x15f.7 (1)
0x160|1e |. | [6]: 30 value 0x160-0x160.7 (1)
0x160| 20 | | [7]: 32 value 0x161-0x161.7 (1)
0x160| 21 | ! | [8]: 33 value 0x162-0x162.7 (1)
0x160| 21 | ! | [9]: 33 value 0x163-0x163.7 (1)
0x160| 21 | ! | [10]: 33 value 0x164-0x164.7 (1)
0x160| 21 | ! | [11]: 33 value 0x165-0x165.7 (1)
0x160| 21 | ! | [12]: 33 value 0x166-0x166.7 (1)
0x160| 21 | ! | [13]: 33 value 0x167-0x167.7 (1)
| | | anotations[0:5]: 0x168-0x181.7 (26)
0x160| 73 6f 6d 65 74 61 62 6c| sometabl| [0]: "sometable" value 0x168-0x171.7 (10)
0x170|65 00 |e. |
0x170| 02 0d 61 00 | ..a. | [1]: "\x02\ra" value 0x172-0x175.7 (4)
0x170| 04 09 62 00 | ..b. | [2]: "\x04\tb" value 0x176-0x179.7 (4)
0x170| 01 08 66 31 00 | ..f1. | [3]: "\x01\bf1" value 0x17a-0x17e.7 (5)
0x170| 01| .| [4]: "\x01\a" value 0x17f-0x181.7 (3)
0x180|07 00 |.. |
0x180| 00| | .| | end: 0 0x182-0x182.7 (1)

0 comments on commit 64c11be

Please sign in to comment.