package gosym
import (
+ "bytes"
"encoding/binary"
"sync"
)
filetab []byte
nfiletab uint32
fileMap map[string]uint32
+ strings map[uint32]string // interned substrings of Data, keyed by offset
}
// NOTE(rsc): This is wrong for GOARCH=arm, which uses a quantum of 4,
// Text must be the start address of the
// corresponding text segment.
func NewLineTable(data []byte, text uint64) *LineTable {
- return &LineTable{Data: data, PC: text, Line: 0}
+ return &LineTable{Data: data, PC: text, Line: 0, strings: make(map[uint32]string)}
}
// Go 1.2 symbol table format.
// string returns a Go string found at off.
func (t *LineTable) string(off uint32) string {
- for i := off; ; i++ {
- if t.Data[i] == 0 {
- return string(t.Data[off:i])
- }
+ if s, ok := t.strings[off]; ok {
+ return s
}
+ i := bytes.IndexByte(t.Data[off:], 0)
+ s := string(t.Data[off : off+uint32(i)])
+ t.strings[off] = s
+ return s
}
// step advances to the next pc, value pair in the encoded table.