非常教程

Go参考手册

调试 | debug

debug/gosym

  • import "debug/gosym"
  • 概述
  • 参数

概述

gosym 包可以访问由 gc 编译器生成的 Go 二进制文件中嵌入的 Go 符号和行号表。

参数

  • type DecodingError
  • func (e *DecodingError) Error() string
  • type Func
  • type LineTable
  • func NewLineTable(data []byte, text uint64) *LineTable
  • func (t *LineTable) LineToPC(line int, maxpc uint64) uint64
  • func (t *LineTable) PCToLine(pc uint64) int
  • type Obj
  • type Sym
  • func (s *Sym) BaseName() string
  • func (s *Sym) PackageName() string
  • func (s *Sym) ReceiverName() string
  • func (s *Sym) Static() bool
  • type Table
  • func NewTable(symtab []byte, pcln *LineTable) (*Table, error)
  • func (t *Table) LineToPC(file string, line int) (pc uint64, fn *Func, err error)
  • func (t *Table) LookupFunc(name string) *Func
  • func (t *Table) LookupSym(name string) *Sym
  • func (t *Table) PCToFunc(pc uint64) *Func
  • func (t *Table) PCToLine(pc uint64) (file string, line int, fn *Func)
  • func (t *Table) SymByAddr(addr uint64) *Sym
  • type UnknownFileError
  • func (e UnknownFileError) Error() string
  • type UnknownLineError
  • func (e *UnknownLineError) Error() string

打包文件

pclntab.go symtab.go

type DecodingError(查看源代码)

DecodingError表示解码符号表时发生错误。

type DecodingError struct {
        // 包含过滤或未导出的字段
}

func (*DecodingError) Error(查看源代码)

func (e *DecodingError) Error() string

type Func(查看源代码)

Func 收集有关单个功能的信息。

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

type LineTable(查看源代码)

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

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

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

大多数情况下,LineTable 的方法应该被视为包的内部细节; 调用者应该使用 Table 上的方法。

type LineTable struct {
        Data []byte
        PC   uint64
        Line int
        // 包含过滤或未导出的字段
}

func NewLineTable(查看源代码)

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

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

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

PCToLine 返回给定程序计数器的行号。调用者应该使用 Table 的 PCToLine 方法。

type Obj(查看源代码)

Obj 表示符号表中的函数集合。

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

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

在Go 1和Go 1.1中,每个软件包为所有 Go 源和每个C源文件创建一个 Obj。

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

type Obj struct {
        // Funcs是Obj中的函数列表。
        Funcs []Func

        // 在Go 1.1和更早版本中,路径是相应符号的列表
        // 到产生Obj的源文件名。
        // 在Go 1.2中,Paths是零。
        // 使用Table.Files的键获取源文件列表。
        Paths []Sym // 元(meta)
}

type Sym(查看源代码)

Sym代表一个符号表项。

type Sym struct {
        Value  uint64
        Type   byte
        Name   string
        GoType uint64
        // 如果此符号是函数符号,则对应Func
        Func *Func
}

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(查看源代码)

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

type Table struct {
        Syms  []Sym
        Funcs []Func
        Files map[string]*Obj // 无论是Go 1.2还是更高版本的二进制文件
        Objs  []Obj           // 无论是Go 1.2还是更高版本的二进制文件
        // 包含过滤或未导出的字段
}

func NewTable(查看源代码)

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

NewTable 对数据中的 Go 符号表进行解码,返回一个内存中表示。

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(查看源代码)

UnknownFileError 表示找不到符号表中的特定文件。

type UnknownFileError string

func (UnknownFileError) Error(查看源代码)

func (e UnknownFileError) Error() string

type UnknownLineError(查看源代码)

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

type UnknownLineError struct {
        File string
        Line int
}

func (*UnknownLineError) Error(查看源代码)

func (e *UnknownLineError) Error() string
Go

Go 是一种编译型语言,它结合了解释型语言的游刃有余,动态类型语言的开发效率,以及静态类型的安全性。它也打算成为现代的,支持网络与多核计算的语言。要满足这些目标,需要解决一些语言上的问题:一个富有表达能力但轻量级的类型系统,并发与垃圾回收机制,严格的依赖规范等等。这些无法通过库或工具解决好,因此Go也就应运而生了。

主页 https://golang.org/
源码 https://go.googlesource.com/go
发布版本 1.9.2

Go目录

1.档案 | archive
2.缓冲区 | bufio
3.内置 | builtin
4.字节 | bytes
5.压缩 | compress
6.容器 | container
7.上下文 | context
8.加密 | crypto
9.数据库 | database
10.调试 | debug
11.编码 | encoding
12.错误 | errors
13. expvar
14.flag
15. fmt
16. go
17.散列 | hash
18.html
19.图像 | image
20.索引 | index
21.io
22.日志 | log
23.数学 | math
24. math/big
25.math/bits
26.math/cmplx
27.math/rand
28.拟态 | mime
29.net
30.net/http
31. net/mail
32. net/rpc
33.net/smtp
34. net/textproto
35. net/url
36.os
37.路径 | path
38.插件 | plugin
39.反射 | reflect
40.正则表达式 | regexp
41.运行时 | runtime
42.排序算法 | sort
43.转换 | strconv
44.字符串 | strings
45.同步 | sync
46.系统调用 | syscall
47.测试 | testing
48.文本 | text
49.时间戳 | time
50.unicode
51.不安全性 | unsafe
52.Go 语言数据类型
53.Go 语言基础语法
54.Go 语言结构
55.Go 语言 select 语句
56.Go 语言 switch 语句
57.Go 语言 if 语句嵌套
58.Go 语言 if…else 语句
59.Go 语言 if 语句
60.Go 语言运算符
61.Go 语言常量
62.Go 语言函数闭包
63.Go 语言函数作为实参
64.Go 语言函数引用传递值
65.Go 语言函数值传递值
66.Go 语言函数
67.Go 语言 goto 语句
68.Go 语言 continue 语句
69.Go 语言 break 语句
70.Go 语言循环嵌套
71.Go 语言 for 循环
72.Go 语言结构体
73.Go 语言指针作为函数参数
74.Go 语言指向指针的指针
75.Go 语言指针数组
76.Go 语言指针
77.Go 语言向函数传递数组
78.Go 语言多维数组
79.Go 语言变量作用域
80.Go 语言函数方法
81.Go 错误处理
82.Go 语言接口
83.Go 语言类型转换
84.Go 语言递归函数
85.Go 语言Map(集合)
86.Go 语言范围(Range)
87.Go 语言切片(Slice)
88.Go 并发
89.Go fmt.Sprintf 格式化字符串