Created
January 2, 2021 20:46
-
-
Save grantseltzer/51c7c0827b95e9a1c07796d6b352076c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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