1
0
mirror of https://github.com/DataDog/go-profiler-notes.git synced 2025-07-15 23:54:16 +02:00
Files
go-profiler-notes/examples/pclnttab/linux.go

39 lines
676 B
Go
Raw Permalink Normal View History

2022-08-19 22:07:20 +02:00
//go:build linux
// +build linux
2021-03-30 14:51:41 +02:00
package main
import (
"debug/elf"
"errors"
"fmt"
"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 := elf.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
}