本文整理汇总了Golang中debug/gosym.NewLineTable函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLineTable函数的具体用法?Golang NewLineTable怎么用?Golang NewLineTable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLineTable函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: obtainGoSymbols
func (dbp *Process) obtainGoSymbols(exe *macho.File, wg *sync.WaitGroup) {
defer wg.Done()
var (
symdat []byte
pclndat []byte
err error
)
if sec := exe.Section("__gosymtab"); sec != nil {
symdat, err = sec.Data()
if err != nil {
fmt.Println("could not get .gosymtab section", err)
os.Exit(1)
}
}
if sec := exe.Section("__gopclntab"); sec != nil {
pclndat, err = sec.Data()
if err != nil {
fmt.Println("could not get .gopclntab section", err)
os.Exit(1)
}
}
pcln := gosym.NewLineTable(pclndat, exe.Section("__text").Addr)
tab, err := gosym.NewTable(symdat, pcln)
if err != nil {
fmt.Println("could not get initialize line table", err)
os.Exit(1)
}
dbp.goSymTable = tab
}
开发者ID:alaska,项目名称:delve,代码行数:34,代码来源:proc_darwin.go
示例2: PCLineTable
func (f *File) PCLineTable() (*gosym.Table, error) {
textStart, symtab, pclntab, err := f.raw.pcln()
if err != nil {
return nil, err
}
return gosym.NewTable(symtab, gosym.NewLineTable(pclntab, textStart))
}
开发者ID:Greentor,项目名称:go,代码行数:7,代码来源:objfile.go
示例3: elfGoSyms
func elfGoSyms(f *elf.File) (*gosym.Table, os.Error) {
text := f.Section(".text")
symtab := f.Section(".gosymtab")
pclntab := f.Section(".gopclntab")
if text == nil || symtab == nil || pclntab == nil {
return nil, nil
}
symdat, err := symtab.Data()
if err != nil {
return nil, err
}
pclndat, err := pclntab.Data()
if err != nil {
return nil, err
}
pcln := gosym.NewLineTable(pclndat, text.Addr)
tab, err := gosym.NewTable(symdat, pcln)
if err != nil {
return nil, err
}
return tab, nil
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:25,代码来源:process.go
示例4: symbolTable
func symbolTable() *gosym.Table {
attempts := []func() (uint64, []byte, []byte, error){
pclnElf,
pclnMacho,
pclnPE,
pclnPlan9,
}
var errors []error
for _, a := range attempts {
textStart, symtab, pclntab, err := a()
if err == nil {
var table *gosym.Table
table, err = gosym.NewTable(symtab, gosym.NewLineTable(pclntab, textStart))
if err == nil {
return table
}
}
errors = append(errors, err)
}
for _, err := range errors {
fmt.Fprintln(os.Stderr, err)
}
flagset.Usage()
os.Exit(1)
panic("unreachable")
}
开发者ID:BenLubar,项目名称:bit,代码行数:29,代码来源:main.go
示例5: main
func main() {
log.SetFlags(0)
log.SetPrefix("addr2line: ")
// pprof expects this behavior when checking for addr2line
if len(os.Args) > 1 && os.Args[1] == "--help" {
printUsage(os.Stdout)
os.Exit(0)
}
flag.Usage = usage
flag.Parse()
if flag.NArg() != 1 {
usage()
}
f, err := os.Open(flag.Arg(0))
if err != nil {
log.Fatal(err)
}
textStart, symtab, pclntab, err := loadTables(f)
if err != nil {
log.Fatalf("reading %s: %v", flag.Arg(0), err)
}
pcln := gosym.NewLineTable(pclntab, textStart)
tab, err := gosym.NewTable(symtab, pcln)
if err != nil {
log.Fatalf("reading %s: %v", flag.Arg(0), err)
}
stdin := bufio.NewScanner(os.Stdin)
stdout := bufio.NewWriter(os.Stdout)
for stdin.Scan() {
p := stdin.Text()
if strings.Contains(p, ":") {
// Reverse translate file:line to pc.
// This was an extension in the old C version of 'go tool addr2line'
// and is probably not used by anyone, but recognize the syntax.
// We don't have an implementation.
fmt.Fprintf(stdout, "!reverse translation not implemented\n")
continue
}
pc, _ := strconv.ParseUint(p, 16, 64)
file, line, fn := tab.PCToLine(pc)
name := "?"
if fn != nil {
name = fn.Name
} else {
file = "?"
line = 0
}
fmt.Fprintf(stdout, "%s\n%s:%d\n", name, file, line)
}
stdout.Flush()
}
开发者ID:TomHoenderdos,项目名称:go-sunos,代码行数:58,代码来源:main.go
示例6: PCLineTable
func (f *File) PCLineTable() (Liner, error) {
// If the raw file implements Liner directly, use that.
// Currently, only Go intermediate objects and archives (goobj) use this path.
if pcln, ok := f.raw.(Liner); ok {
return pcln, nil
}
// Otherwise, read the pcln tables and build a Liner out of that.
textStart, symtab, pclntab, err := f.raw.pcln()
if err != nil {
return nil, err
}
return gosym.NewTable(symtab, gosym.NewLineTable(pclntab, textStart))
}
开发者ID:tsuru,项目名称:tsuru,代码行数:13,代码来源:objfile.go
示例7: processGoInformation
func processGoInformation(f *elf.File) {
gosymtab := getSectionData(f, ".gosymtab")
gopclntab := getSectionData(f, ".gopclntab")
lineTable := gosym.NewLineTable(gopclntab, f.Section(".text").Addr)
table, err := gosym.NewTable(gosymtab, lineTable)
if err != nil {
log.Fatalf("failed making table: %s", err)
}
printSyms(table.Syms)
printFuncs(table.Funcs)
printFiles(table.Files)
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:14,代码来源:gosym.go
示例8: NewExec
// NewExec tries to detect executable type for the given path and returns
// a new executable. It fails if file does not exist, is not a Go executable or
// it's unable to parse the file format.
func NewExec(path string) (*Exec, error) {
typ, symtab, pclntab, text, err := newtbl(path)
if err != nil {
return nil, err
}
lntab := gosym.NewLineTable(pclntab, text)
if lntab == nil {
return nil, ErrNotGoExec
}
tab, err := gosym.NewTable(symtab, lntab)
if err != nil {
return nil, ErrNotGoExec
}
return &Exec{Path: path, Type: typ, table: tab}, nil
}
开发者ID:rjeczalik,项目名称:which,代码行数:18,代码来源:which.go
示例9: main
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
// inspect ELF symbol table
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:45,代码来源:introspection.go
示例10: obtainGoSymbols
func (dbp *Process) obtainGoSymbols(exe *pe.File, wg *sync.WaitGroup) {
defer wg.Done()
_, symdat, pclndat, err := pcln(exe)
if err != nil {
fmt.Println("could not get Go symbols", err)
os.Exit(1)
}
pcln := gosym.NewLineTable(pclndat, uint64(exe.Section(".text").Offset))
tab, err := gosym.NewTable(symdat, pcln)
if err != nil {
fmt.Println("could not get initialize line table", err)
os.Exit(1)
}
dbp.goSymTable = tab
}
开发者ID:DuoSoftware,项目名称:v6engine-deps,代码行数:18,代码来源:proc_windows.go
示例11: makeTable
func makeTable(f debugFile) (*gosym.Table, error) {
symdat, err := f.Symtab()
if err != nil {
return nil, err
}
pclndat, err := f.Pclntab()
if err != nil {
return nil, err
}
pcln := gosym.NewLineTable(pclndat, f.TextAddr())
tab, err := gosym.NewTable(symdat, pcln)
if err != nil {
return nil, err
}
return tab, nil
}
开发者ID:rainycape,项目名称:gondola,代码行数:18,代码来源:pretty.go
示例12: findAddr
func findAddr(r io.ReaderAt, sym string) (uintptr, error) {
file, err := elf.NewFile(r)
if err != nil {
return 0, err
}
defer file.Close()
var (
textStart uint64
symtab, pclntab []byte
)
if sect := file.Section(".text"); sect != nil {
textStart = sect.Addr
}
if sect := file.Section(".gosymtab"); sect != nil {
if symtab, err = sect.Data(); err != nil {
return 0, err
}
}
if sect := file.Section(".gopclntab"); sect != nil {
if pclntab, err = sect.Data(); err != nil {
return 0, err
}
}
tab, err := gosym.NewTable(symtab, gosym.NewLineTable(pclntab, textStart))
if err != nil {
return 0, err
}
fn := tab.LookupFunc(sym)
if fn == nil {
return 0, fmt.Errorf("could not find symbol %q", sym)
}
return uintptr(fn.Entry), nil
}
开发者ID:EricLagergren,项目名称:patch,代码行数:37,代码来源:main.go
示例13: main
func main() {
log.SetFlags(0)
log.SetPrefix("objdump: ")
flag.Usage = usage
flag.Parse()
if flag.NArg() != 1 && flag.NArg() != 3 {
usage()
}
if *symregexp != "" {
re, err := regexp.Compile(*symregexp)
if err != nil {
log.Fatalf("invalid -s regexp: %v", err)
}
symRE = re
}
f, err := os.Open(flag.Arg(0))
if err != nil {
log.Fatal(err)
}
textStart, textData, symtab, pclntab, err := loadTables(f)
if err != nil {
log.Fatalf("reading %s: %v", flag.Arg(0), err)
}
syms, goarch, err := loadSymbols(f)
if err != nil {
log.Fatalf("reading %s: %v", flag.Arg(0), err)
}
// Filter out section symbols, overwriting syms in place.
keep := syms[:0]
for _, sym := range syms {
switch sym.Name {
case "text", "_text", "etext", "_etext":
// drop
default:
keep = append(keep, sym)
}
}
syms = keep
disasm := disasms[goarch]
if disasm == nil {
log.Fatalf("reading %s: unknown architecture", flag.Arg(0))
}
lookup := func(addr uint64) (string, uint64) {
i := sort.Search(len(syms), func(i int) bool { return syms[i].Addr > addr })
if i > 0 {
s := syms[i-1]
if s.Addr <= addr && addr < s.Addr+uint64(s.Size) && s.Name != "etext" && s.Name != "_etext" {
return s.Name, s.Addr
}
}
return "", 0
}
pcln := gosym.NewLineTable(pclntab, textStart)
tab, err := gosym.NewTable(symtab, pcln)
if err != nil {
log.Fatalf("reading %s: %v", flag.Arg(0), err)
}
if flag.NArg() == 1 {
// disassembly of entire object - our format
dump(tab, lookup, disasm, syms, textData, textStart)
os.Exit(exitCode)
}
// disassembly of specific piece of object - gnu objdump format for pprof
gnuDump(tab, lookup, disasm, textData, textStart)
os.Exit(exitCode)
}
开发者ID:h8liu,项目名称:golang,代码行数:77,代码来源:main.go
注:本文中的debug/gosym.NewLineTable函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论