美文网首页
Golang标准库——debug/gosym

Golang标准库——debug/gosym

作者: DevilRoshan | 来源:发表于2020-09-19 00:04 被阅读0次

gosym

包gosym实现了对gc编译器生成的Go二进制文件中嵌入的Go符号和行号表的访问。

type DecodingError

type DecodingError struct {
    off int
    msg string
    val interface{}
}

DecodingError表示符号表解码期间的错误。

func (*DecodingError) Error

func (e *DecodingError) Error() string

type Func

type Func struct {
    Entry uint64
    *Sym
    End       uint64
    Params    []*Sym
    Locals    []*Sym
    FrameSize int
    LineTable *LineTable
    Obj       *Obj
}

单个function的信息

type LineTable

type LineTable struct {
    Data []byte
    PC   uint64
    Line int
    // contains filtered or unexported fields
}

LineTable是将程序计数器映射到行号的数据结构。

在Go 1.1和更早版本中,每个函数(由Func表示)都有自己的LineTable,并且行号对应于程序中所有文件中所有源行的编号。 然后必须将该绝对行号分别转换为文件名和文件内的行号。

在Go 1.2中,数据的格式已更改,因此整个程序只有一个LineTable,由所有Funcs共享,并且没有绝对的行号,只有特定文件中的行号。

在大多数情况下,LineTable的方法应视为程序包的内部细节。 调用者应改用Table上的方法。

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.

func NewLineTable

func NewLineTable(data []byte, text uint64) *LineTable

NewLineTable返回对应于编码数据的新PC /线表。 文本必须是相应文本段的起始地址。

func (*LineTable) LineToPC

func (t *LineTable) LineToPC(line int, maxpc uint64) uint64

LineToPC返回给定行号的程序计数器,仅考虑maxpc之前的程序计数器。 调用者应改用Table的LineToPC方法。

func (*LineTable) PCToLine

func (t *LineTable) PCToLine(pc uint64) int

PICToLine返回给定程序计数器的行号。 调用者应改用Tables PICToLine方法。

type Obj

type Obj struct {
    // Funcs is a list of functions in the Obj.
    Funcs []Func

    // In Go 1.1 and earlier, Paths is a list of symbols corresponding
    // to the source file names that produced the Obj.
    // In Go 1.2, Paths is nil.
    // Use the keys of Table.Files to obtain a list of source files.
    Paths []Sym // meta
}

Obj代表符号表中的功能集合。

将二进制文件划分为单独的Objs的确切方法是符号表格式的内部细节。

在Go的早期版本中,每个源文件都变成了不同的Obj。

在Go 1和Go 1.1中,每个程序包为所有Go源产生一个Obj,为每个C源文件产生一个Obj。

在Go 1.2中,整个程序只有一个Obj。

type [Sym

type Sym struct {
    Value  uint64
    Type   byte
    Name   string
    GoType uint64
    // If this symbol is a function symbol, the corresponding Func
    Func *Func
}

Sym表示单个符号表入口。

func (*Sym) BaseName

func (s *Sym) BaseName() string

BaseName返回符号名称,而不包含程序包或接收者名称。

func (*Sym) PackageName

func (s *Sym) PackageName() string

PackageName返回符号名称的包部分,如果没有则返回空字符串。

func (*Sym) ReceiverName

func (s *Sym) ReceiverName() string

ReceiverName返回此符号的接收者类型名称,如果没有,则返回空字符串。

func (*Sym) Static

func (s *Sym) Static() bool

静态报告此符号是否为静态(在文件外部不可见)。

type Table

type Table struct {
    Syms  []Sym
    Funcs []Func
    Files map[string]*Obj // nil for Go 1.2 and later binaries
    Objs  []Obj           // nil for Go 1.2 and later binaries
    // contains filtered or unexported fields
}

表代表Go符号表。 它存储从程序中解码的所有符号,并提供在符号,名称和地址之间转换的方法。

func NewTable

func NewTable(symtab []byte, pcln *LineTable) (*Table, error)

NewTable decodes the Go symbol table in data, returning an in-memory representation.

func (*Table) LineToPC

func (t *Table) LineToPC(file string, line int) (pc uint64, fn *Func, err error)

LineToPC在命名文件的给定行中查找第一个程序计数器。 如果在查找此行时出错,则返回UnknownPathError或UnknownLineError。

func (*Table) LookupFunc

func (t *Table) LookupFunc(name string) *Func

LookupFunc返回具有给定名称的文本,数据或bss符号,如果找不到此类符号,则返回nil。

func (*Table) LookupSym

func (t *Table) LookupSym(name string) *Sym

LookupSym返回具有给定名称的文本,数据或bss符号,如果找不到此类符号,则返回nil。

func (*Table) PCToFunc

func (t *Table) PCToFunc(pc uint64) *Func

PCToFunc返回包含程序计数器pc的函数,如果没有该函数,则返回nil。

func (*Table) PCToLine

func (t *Table) PCToLine(pc uint64) (file string, line int, fn *Func)

PCToLine查找程序计数器的行号信息。 如果没有信息,则返回fn == nil。

func (*Table) SymByAddr

func (t *Table) SymByAddr(addr uint64) *Sym

SymByAddr返回从给定地址开始的文本,数据或bss符号。

type UnknownFileError

type UnknownFileError string

UnknownFileError表示无法在符号表中找到特定文件。

func (UnknownFileError) Error

func (e UnknownFileError) Error() string

type UnknownLineError

type UnknownLineError struct {
    File string
    Line int
}

UnknownLineError表示无法将行映射到程序计数器,这是因为该行超出了文件的范围,或者因为给定行上没有代码。

func (*UnknownLineError) Error

func (e *UnknownLineError) Error() string

相关文章

网友评论

      本文标题:Golang标准库——debug/gosym

      本文链接:https://www.haomeiwen.com/subject/acqdyktx.html