Skip to content

Instantly share code, notes, and snippets.

@grantseltzer
Created January 2, 2021 20:46
Show Gist options
  • Save grantseltzer/51c7c0827b95e9a1c07796d6b352076c to your computer and use it in GitHub Desktop.
Save grantseltzer/51c7c0827b95e9a1c07796d6b352076c to your computer and use it in GitHub Desktop.
package main
import (
"debug/dwarf"
"debug/elf"
"fmt"
"io"
"log"
"os"
)
func main() {
elfFile, err := elf.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
dwarfData, err := elfFile.DWARF()
if err != nil {
log.Fatal(err)
}
entryReader := dwarfData.Reader()
for {
// Read all entries in sequence
entry, err := entryReader.Next()
if err == io.EOF {
// We've reached the end of DWARF entries
break
}
// Check if this entry is a function
if entry.Tag == dwarf.TagSubprogram {
// Go through fields
for _, field := range entry.Field {
if field.Attr == dwarf.AttrName {
fmt.Println(field.Val.(string))
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment