-
Notifications
You must be signed in to change notification settings - Fork 7
/
pc2ln.go
69 lines (56 loc) · 1.29 KB
/
pc2ln.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package ciqdb
import (
"encoding/binary"
"strconv"
"strings"
)
type CodeTable struct {
PRGSection
Map []PCMap
}
func (c *CodeTable) String() string {
var buf strings.Builder
buf.WriteString(c.PRGSection.String() + "\n")
for _, p := range c.Map {
buf.WriteString(" " + p.String() + "\n")
}
return buf.String()
}
type PCMap struct {
pc int
file string
symbol string
line int
}
func (p *PCMap) String() string {
return p.file + ":" + strconv.Itoa(p.line) + " " + p.symbol + " (pc " + strconv.Itoa(p.pc) + ")"
}
func parsePCTable(p *PRG, t SecType, length int, data []byte) *CodeTable {
table := CodeTable{
PRGSection: PRGSection{
Type: t,
length: length,
},
}
var dataSec *DataSection
for _, s := range p.Sections {
if s.getType() == SectionData {
dataSec = s.(*DataSection)
}
}
if dataSec == nil {
return nil
}
// skip first two data bytes. Count? Length?
for i := 2; i < len(data); {
thing := PCMap{
pc: int(binary.BigEndian.Uint32(data[i : i+4])),
file: dataSec.getString(int(binary.BigEndian.Uint32(data[i+4 : i+8]))),
symbol: dataSec.getString(int(binary.BigEndian.Uint32(data[i+8 : i+12]))),
line: int(binary.BigEndian.Uint32(data[i+12 : i+16])),
}
i += 16
table.Map = append(table.Map, thing)
}
return &table
}