Imports #
"bytes"
"encoding/binary"
"fmt"
"strconv"
"strings"
"bytes"
"encoding/binary"
"sort"
"sync"
"bytes"
"encoding/binary"
"fmt"
"strconv"
"strings"
"bytes"
"encoding/binary"
"sort"
"sync"
var bigEndianSymtab = []byte{...}
disableRecover causes this package not to swallow panics. This is useful when making changes.
const disableRecover = false
const go116magic = 0xfffffffa
const go118magic = 0xfffffff0
const go120magic = 0xfffffff1
const go12magic = 0xfffffffb
var littleEndianSymtab = []byte{...}
var oldLittleEndianSymtab = []byte{...}
NOTE(rsc): This is wrong for GOARCH=arm, which uses a quantum of 4, but we have no idea whether we're using arm or not. This only matters in the old (pre-Go 1.2) symbol table format, so it's not worth fixing.
const oldQuantum = 1
const ver11
const ver116
const ver118
const ver12
const ver120
const verUnknown version = iota
UnknownFileError represents a failure to find the specific file in the symbol table.
type UnknownFileError string
version of the pclntab
type version int
DecodingError represents an error during the decoding of the symbol table.
type DecodingError struct {
off int
msg string
val any
}
A Func collects information about a single function.
type Func struct {
Entry uint64
*Sym
End uint64
Params []*Sym
Locals []*Sym
FrameSize int
LineTable *LineTable
Obj *Obj
}
A LineTable is a data structure mapping program counters to line numbers. In Go 1.1 and earlier, each function (represented by a [Func]) had its own LineTable, and the line number corresponded to a numbering of all source lines in the program, across all files. That absolute line number would then have to be converted separately to a file name and line number within the file. In Go 1.2, the format of the data changed so that there is a single LineTable for the entire program, shared by all Funcs, and there are no absolute line numbers, just line numbers within specific files. For the most part, LineTable's methods should be treated as an internal detail of the package; callers should use the methods on [Table] instead.
type LineTable struct {
Data []byte
PC uint64
Line int
mu sync.Mutex
version version
binary binary.ByteOrder
quantum uint32
ptrsize uint32
textStart uint64
funcnametab []byte
cutab []byte
funcdata []byte
functab []byte
nfunctab uint32
filetab []byte
pctab []byte
nfiletab uint32
funcNames map[uint32]string
strings map[uint32]string
fileMap map[string]uint32
}
An Obj represents a collection of functions in a symbol table. The exact method of division of a binary into separate Objs is an internal detail of the symbol table format. In early versions of Go each source file became a different Obj. In Go 1 and Go 1.1, each package produced one Obj for all Go sources and one Obj per C source file. In Go 1.2, there is a single Obj for the entire program.
type Obj struct {
Funcs []Func
Paths []Sym
}
A Sym represents a single symbol table entry.
type Sym struct {
Value uint64
Type byte
Name string
GoType uint64
Func *Func
goVersion version
}
Table represents a Go symbol table. It stores all of the symbols decoded from the program and provides methods to translate between symbols, names, and addresses.
type Table struct {
Syms []Sym
Funcs []Func
Files map[string]*Obj
Objs []Obj
go12line *LineTable
}
UnknownLineError represents a failure to map a line to a program counter, either because the line is beyond the bounds of the file or because there is no code on the given line.
type UnknownLineError struct {
File string
Line int
}
funcData is memory corresponding to an _func struct.
type funcData struct {
t *LineTable
data []byte
}
funcTab is memory corresponding to a slice of functab structs, followed by an invalid PC. A functab struct is a PC and a func offset.
type funcTab struct {
*LineTable
sz int
}
type sym struct {
value uint64
gotype uint64
typ byte
name []byte
}
BaseName returns the symbol name without the package or receiver name.
func (s *Sym) BaseName() string
Count returns the number of func entries in f.
func (f funcTab) Count() int
func (e *DecodingError) Error() string
func (e *UnknownLineError) Error() string
func (e UnknownFileError) Error() string
IsZero reports whether f is the zero value.
func (f funcData) IsZero() bool
LineToPC looks up the first program counter on the given line in the named file. It returns [UnknownFileError] or [UnknownLineError] if there is an error looking up this line.
func (t *Table) LineToPC(file string, line int) (pc uint64, fn *Func, err error)
LineToPC returns the program counter for the given line number, considering only program counters before maxpc. Deprecated: Use Table's LineToPC method instead.
func (t *LineTable) LineToPC(line int, maxpc uint64) uint64
LookupFunc returns the text, data, or bss symbol with the given name, or nil if no such symbol is found.
func (t *Table) LookupFunc(name string) *Func
LookupSym returns the text, data, or bss symbol with the given name, or nil if no such symbol is found.
func (t *Table) LookupSym(name string) *Sym
NewLineTable returns a new PC/line table corresponding to the encoded data. Text must be the start address of the corresponding text segment, with the exact value stored in the 'runtime.text' symbol. This value may differ from the start address of the text segment if binary was built with cgo enabled.
func NewLineTable(data []byte, text uint64) *LineTable
NewTable decodes the Go symbol table (the ".gosymtab" section in ELF), returning an in-memory representation. Starting with Go 1.3, the Go symbol table no longer includes symbol data.
func NewTable(symtab []byte, pcln *LineTable) (*Table, error)
PCToFunc returns the function containing the program counter pc, or nil if there is no such function.
func (t *Table) PCToFunc(pc uint64) *Func
PCToLine looks up line number information for a program counter. If there is no information, it returns fn == nil.
func (t *Table) PCToLine(pc uint64) (file string, line int, fn *Func)
PCToLine returns the line number for the given program counter. Deprecated: Use Table's PCToLine method instead.
func (t *LineTable) PCToLine(pc uint64) int
PackageName returns the package part of the symbol name, or the empty string if there is none.
func (s *Sym) PackageName() string
ReceiverName returns the receiver type name of this symbol, or the empty string if there is none. A receiver name is only detected in the case that s.Name is fully-specified with a package name.
func (s *Sym) ReceiverName() string
Static reports whether this symbol is static (not visible outside its file).
func (s *Sym) Static() bool
SymByAddr returns the text, data, or bss symbol starting at the given address.
func (t *Table) SymByAddr(addr uint64) *Sym
func (o *Obj) alineFromLine(path string, line int) (int, error)
func (f funcData) cuOffset() uint32
func (f funcData) deferreturn() uint32
entryPC returns the func's entry PC.
func (f *funcData) entryPC() uint64
field returns the nth field of the _func struct. It panics if n == 0 or n > 9; for n == 0, call f.entryPC. Most callers should use a named field accessor (just above).
func (f funcData) field(n uint32) uint32
findFileLine scans one function in the binary looking for a program counter in the given file on the given line. It does so by running the pc-value tables mapping program counter to file number. Since most functions come from a single file, these are usually short and quick to scan. If a file match is found, then the code goes to the expense of looking for a simultaneous line number match.
func (t *LineTable) findFileLine(entry uint64, filetab uint32, linetab uint32, filenum int32, line int32, cutab []byte) uint64
findFunc returns the funcData corresponding to the given program counter.
func (t *LineTable) findFunc(pc uint64) funcData
funcData returns the ith funcData in t.functab.
func (t *LineTable) funcData(i uint32) funcData
funcName returns the name of the function found at off.
func (t *LineTable) funcName(off uint32) string
funcOff returns the funcdata offset of the i'th func in f.
func (f funcTab) funcOff(i int) uint64
funcTab returns t's funcTab.
func (t *LineTable) funcTab() funcTab
functabFieldSize returns the size in bytes of a single functab field.
func (t *LineTable) functabFieldSize() int
go12Funcs returns a slice of Funcs derived from the Go 1.2+ pcln table.
func (t *LineTable) go12Funcs() []Func
go12LineToPC maps a (file, line) pair to a program counter for the Go 1.2+ pcln table.
func (t *LineTable) go12LineToPC(file string, line int) (pc uint64)
go12MapFiles adds to m a key for every file in the Go 1.2 LineTable. Every key maps to obj. That's not a very interesting map, but it provides a way for callers to obtain the list of files in the program.
func (t *LineTable) go12MapFiles(m map[string]*Obj, obj *Obj)
go12PCToFile maps program counter to file name for the Go 1.2+ pcln table.
func (t *LineTable) go12PCToFile(pc uint64) (file string)
go12PCToLine maps program counter to line number for the Go 1.2+ pcln table.
func (t *LineTable) go12PCToLine(pc uint64) (line int)
initFileMap initializes the map from file name to file number.
func (t *LineTable) initFileMap()
isGo12 reports whether this is a Go 1.2 (or later) symbol table.
func (t *LineTable) isGo12() bool
func (o *Obj) lineFromAline(aline int) (string, int)
func (f funcData) nameOff() uint32
nameWithoutInst returns s.Name if s.Name has no brackets (does not reference an instantiated type, function, or method). If s.Name contains brackets, then it returns s.Name with all the contents between (and including) the outermost left and right bracket removed. This is useful to ignore any extra slashes or dots inside the brackets from the string searches below, where needed.
func (s *Sym) nameWithoutInst() string
func (t *LineTable) parse(targetPC uint64, targetLine int) (b []byte, pc uint64, line int)
parsePclnTab parses the pclntab, setting the version.
func (t *LineTable) parsePclnTab()
pc returns the PC of the i'th func in f.
func (f funcTab) pc(i int) uint64
func (f funcData) pcfile() uint32
func (f funcData) pcln() uint32
pcvalue reports the value associated with the target pc. off is the offset to the beginning of the pc-value table, and entry is the start PC for the corresponding function.
func (t *LineTable) pcvalue(off uint32, entry uint64, targetpc uint64) int32
readvarint reads, removes, and returns a varint from *pp.
func (t *LineTable) readvarint(pp *[]byte) uint32
func (t *LineTable) slice(pc uint64) *LineTable
step advances to the next pc, value pair in the encoded table.
func (t *LineTable) step(p *[]byte, pc *uint64, val *int32, first bool) bool
string returns a Go string found at off.
func (t *LineTable) string(off uint32) string
stringFrom returns a Go string found at off from a position.
func (t *LineTable) stringFrom(arr []byte, off uint32) string
uint returns the uint stored at b.
func (f funcTab) uint(b []byte) uint64
uintptr returns the pointer-sized value encoded at b. The pointer size is dictated by the table being read.
func (t *LineTable) uintptr(b []byte) uint64
func walksymtab(data []byte, fn func(sym) error) error
Generated with Arrow