You've already forked go-profiler-notes
mirror of
https://github.com/DataDog/go-profiler-notes.git
synced 2025-07-12 23:50:13 +02:00
38 lines
683 B
Go
38 lines
683 B
Go
//go:build darwin
|
|
// +build darwin
|
|
|
|
package main
|
|
|
|
import (
|
|
"debug/gosym"
|
|
"debug/macho"
|
|
"os"
|
|
)
|
|
|
|
// from https://github.com/lizrice/debugger-from-scratch/blob/master/symbols.go
|
|
func goSymTable() (*gosym.Table, error) {
|
|
exe, err := macho.Open(os.Args[0])
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
defer exe.Close()
|
|
|
|
addr := exe.Section("__text").Addr
|
|
|
|
lineTableData, err := exe.Section("__gopclntab").Data()
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
lineTable := gosym.NewLineTable(lineTableData, addr)
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
|
|
symTableData, err := exe.Section("__gosymtab").Data()
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return gosym.NewTable(symTableData, lineTable)
|
|
}
|