Created
January 25, 2021 14:24
-
-
Save wthorp/cdafd0c9c16de9cfe50bb13dd59cb066 to your computer and use it in GitHub Desktop.
Dump linked files from Dwarf debugging data
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/macho" | |
"fmt" | |
"os" | |
"strings" | |
) | |
func main() { | |
path := os.Args[1] | |
fh, err := macho.Open(path) | |
if err != nil { | |
fmt.Println("ERROR!!!!") | |
return | |
} | |
defer fh.Close() | |
data, err := fh.DWARF() | |
if err != nil { | |
fmt.Println("ERROR!!!!") | |
return | |
} | |
reader := data.Reader() | |
minioFiles := make(map[string]bool) | |
for { | |
entry, err := reader.Next() | |
if err != nil { | |
fmt.Println("ERROR!!!!") | |
return | |
} | |
if entry == nil { | |
break | |
} | |
if entry.Tag != dwarf.TagCompileUnit { | |
reader.SkipChildren() | |
continue | |
} | |
lr, lrerr := data.LineReader(entry) | |
if lrerr != nil { | |
fmt.Println("ERROR!!!!") | |
return | |
} | |
if lr != nil { | |
files := lr.Files() | |
for _, file := range files { | |
if file != nil { | |
if strings.Contains(file.Name, "storj/minio") { | |
minioFiles[file.Name] = true | |
} | |
} | |
} | |
} | |
} | |
for file, _ := range minioFiles { | |
fmt.Println(file) | |
} | |
fmt.Println(len(minioFiles), " files") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment