1
0
mirror of https://github.com/DataDog/go-profiler-notes.git synced 2025-07-12 23:50:13 +02:00
Files

38 lines
683 B
Go
Raw Permalink Normal View History

2022-08-19 22:07:20 +02:00
//go:build darwin
// +build darwin
2021-03-30 14:51:41 +02:00
package main
import (
2022-08-19 22:07:20 +02:00
"debug/gosym"
2021-03-30 14:51:41 +02:00
"debug/macho"
"os"
)
2022-08-19 22:07:20 +02:00
// from https://github.com/lizrice/debugger-from-scratch/blob/master/symbols.go
func goSymTable() (*gosym.Table, error) {
exe, err := macho.Open(os.Args[0])
2021-03-30 14:51:41 +02:00
if err != nil {
2022-08-19 22:07:20 +02:00
return nil, nil
2021-03-30 14:51:41 +02:00
}
2022-08-19 22:07:20 +02:00
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
2021-03-30 14:51:41 +02:00
}
2022-08-19 22:07:20 +02:00
symTableData, err := exe.Section("__gosymtab").Data()
if err != nil {
return nil, nil
}
return gosym.NewTable(symTableData, lineTable)
2021-03-30 14:51:41 +02:00
}